views:

136

answers:

1

I have a large table that I want to map to a few entities.

Say the table looks like this: Thing(ThingId, Property1...Property20)

Now I have my entities:

public abstract class ThingBase
{
    public int ThingId { get; set; }
    public string Property1 { get; set; }
    public string Property2 { get; set; }
}

public class ThingSummary : ThingBase
{
    public string Property3 { get; set; }    
}

public class Thing : ThingBase
{
    public string Property3 { get; set; }
    //...
    public string Property20 { get; set; }
}

How do I set up my DbContext so it will work? I had:

public DbSet<ThingSummary> ThingSummaries { get; set; }

public DbSet<Thing> Things { get; set; }

but I get an error "Invalid object name 'dbo.ThingSummaries'." when I try to query.

I have tried adding to OnModelCreating:

modelBuilder.Entity<ThingSummary>().MapSingleType().ToTable("Things");

but this did not seem to do anything.

Any ideas?

A: 

I think you can't have ThingSummaries. You can only have Things. You also can't use MapSingleType because it says that only single type will be mapped to the table. You have to use MapHiearchy instead. I posted example of such mapping in this question.

Ladislav Mrnka