EF代码第一列表< DateTime>不创建表 [英] EF code first List<DateTime> not creating table
问题描述
public class Activity
{
public Guid Id {get;组; }
public string描述{get;组; }
public List< DateTime> DateDone {get;组; }
< snip>
public Activity()
{
if(DateDone == null)
DateDone = new List< DateTime>();
}
}
我重建项目,然后运行MVC3应用程序数据库生成(确认,我添加和删除列),我的数据被种子(当我修改种子的数据时,它在屏幕上更改)
我能够:
var activity = db.Activities.Find(id);
activity.DateDone = DateTime.Now;
db.SaveChanges();
但数据未保存。我已经检查了数据库,因为只有一个表(活动),它有所有适当的字段。我希望它应该有一个第二个表,但ActivityDateDone有两个字段,ActivityGuid& DateDone。
在这项工作中我缺少什么?
实体框架不支持原始类型的集合。
您需要定义一个单独的类来保存DateTimes。
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?
Entity Framework does not support collections of primitive types.
You need to define a separate class to hold the DateTimes.
这篇关于EF代码第一列表< DateTime>不创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!