Search code examples
c#.netentity-framework-4code-first

EF code first List<DateTime> not creating table


I am creating a very simple EF4 code first project with one entity.

public class Activity
{
    public Guid Id { get; set; }
    public string Description { get; set; }
    public List<DateTime> DateDone { get; set; }
    <snip>

    public Activity()
    {
        if(DateDone==null)
            DateDone = new List<DateTime>();
    }
}

I rebuild my project and then run the MVC3 app and the database generates (confirmed, I have added and removed columns), my data is seeded (it changes on screen when I modify the seeded data)

I am able to:

var activity = db.Activities.Find(id);
activity.DateDone = DateTime.Now;
db.SaveChanges();

But the data isn't saved. I have checked the database as there is only the one table (Activity) and it has all the appropriate fields. I expect it should have a second table though, ActivityDateDone with two fields, ActivityGuid & DateDone.

What am I missing on making this work?


Solution

  • Entity Framework does not support collections of primitive types.

    You need to define a separate class to hold the DateTimes.