实体框架6.0和映射错误

时间:2014-11-25 08:58:18

标签: c# entity-framework

我需要在两个表上映射下面的类 -

public class Centre
{
    public string CentreID { get; set;}
    public string Name { get; set;}
    public int Order { get; set;}
    public string InfoText { get; set; }
    public string Description { get; set; }
}

使用的映射是

modelBuilder.Entity<Centre>()
    .Map(m =>
            {
                m.Properties(t => new { t.CentreID, t.Name, t.Order });
                m.ToTable("Centres");
            })
.Map(m =>
        {
            m.Property(t => t.Description).HasColumnName("InfoText");
            m.ToTable("CentreContents");
            m.Requires("Attribute").HasValue("Description");
        })
.Map(m =>
        {
            //m.Properties(t => new { t.InfoText });
            m.Property(t => t.InfoText);
            m.ToTable("CentreContents");
            m.Requires("Attribute").HasValue("Intro");
        });

前2张地图按预期工作。添加第3个映射会出错。预期的是,存在一对多关系,并且链接表中的每个记录都需要映射到属性上。数据库已存在于应用程序中,无法更改结构。有了视图,它可以但不想为它创建视图。

1 个答案:

答案 0 :(得分:0)

尝试在声明的这一部分中删除半冒号...

                });
        .Map(m =>

哦,详细说明错误可能非常有用。

相关问题