I have the following class hierarchy:
public class RealPeople { } public class Users : RealPeople { } public class People : RealPeople { }
In my dbContext, I defined dbSet for RealPeople and in the OnModelCreating procedure, I specified shared tables for people and users:
modelBuilder.Entity<Users>().ToTable("Users"); modelBuilder.Entity<People>().ToTable("People");
This creates an appropriate complete hierarchy in my database with three matching tables. The problem occurs when I want to get the Users list in my database. It:
List = (from Reg in PersistentMgr.RealPeople select (Users)Reg) .ToList();
or that:
List = (from Reg in PersistentMgr.RealPeople select (Users)((RealPeople)Reg)) .ToList();
Throws an exception:
LINQ can only use primitive model types.
So, I can not attribute RealPeople to the corresponding Users subclass. Any ideas on this?
Alvaro
source share