I am using entity framework code first, I have 2 entities declared like so:
[Table("BaseTable")]
public class BaseEntity
{
public string SomeProperty{get; set;}
}
[Table("DerivedTable")]
public class DerivedEntity
: BaseEntity
{
public string SomeOtherProperty {get; set;}
}
The problem is when I call the generic set method on the dbcontext it always returns the entities as DerivedEntity types. (EF is setting up the correct table mapping in the database just not returing the expected entity type from the set() method)
DbContext.Set<BaseEntity>();
How can I force Set<BaseEntity>(); to return the entities as type BaseEntity so I can only update that table?
You cannot. EF works on entity level not on table level. So if your entity is of type
DerivedEntityit will never be loaded asBaseEntityonly. When you modify attached entity EF will build update command only for modified columns so it should not modify your second table if you are only changing property fromBaseEntitytable.