EF代码第一列表< DateTime>不创建表 [英] EF code first List<DateTime> not creating table

查看:192
本文介绍了EF代码第一列表< DateTime>不创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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代码第一列表&lt; DateTime&gt;不创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆