Reputation: 1853
I'm having a lot of difficulty with the Entity Model Framework.
I'm just learning how to use this, so please bear with me.
This is the exception, along with the line of code that it gets thrown on:
This is what the model looks like, along with the model that it inherits from
This is what the mapping details looks like: (Top of if statement was cut off)
Here's what AccountContext looks like
If I didn't provide enough information then please let me know
How do I map the "User" Entity?
Upvotes: 2
Views: 1768
Reputation: 177133
You have a class hierarchy there and there are three different strategies for inheritance mapping: TPH, TPT and TPC.
As far as I understand in all three strategies you need to include the Base class into you DbContext:
public class AccountContext : DbContext
{
public DbSet<BaseModel> BaseModels { get; set; }
}
This leads automatically to TPH mapping. For the other two strategies you need additional mappings either by data annotations or in Fluent API.
Edit
To query for your derived classes (like User
) you can work with the OfType
method, for instance:
UserDb.BaseModels.OfType<User>().ToList()
This would return all entities of type User
into a list.
Upvotes: 3