简体   繁体   English

实体框架6.0和映射错误

[英]Entity Framework 6.0 and Error with mapping

I need to map following class on two tables - 我需要将以下课程映射到两个表上-

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; }
}

And the mapping used is 和使用的映射是

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");
        });

The first 2 map works as expected. 前两个地图按预期工作。 Adding 3rd map gives error. 添加第三张地图会出错。 What expected is , there is a one to many relation and each record from linked table needs to be mapped on a property. 所期望的是,存在一对多的关系,并且链接表中的每个记录都需要映射到一个属性上。 The database is already existing in the application and not possible to change the structure. 该数据库已存在于应用程序中,无法更改结构。 With view it is possible but don't want to create view for same. 使用视图是可能的,但不想为其创建视图。

Try removing the semi colon in this part of your statement... 尝试在语句的这一部分中删除分号...

                });
        .Map(m =>

Oh and detailing the error can be pretty helpful. 哦,详细说明错误可能会很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM