简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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