Entity Framework inheritance: sort/group by type? -
entity framework (and ria services, use with) support inheritance nicely. database mapping can single-table or multi-table, , in first case database table includes designator column containing type designator.
obviously designator not visible in model, though it's 1 have in order order , group over.
do have introduce additional explicit type designator in base class if that's want or there nicer way order or group type in way?
i'm using ef5.
yes, can imagine scenarios you'd want list of base types. unfortunately there no way discriminator (designator) in conceptual model. way can think of like
db.baseobjects.where(b => ...) .asenumerable().select (b => new {b.gettype().name, b } )
after can sort/group type name. can't project (select
) before asenumerable
, way restrict size of data filtering (where
).
there trick discriminator column visible property in class model. can create computed column in table, displays value of real discriminator column, , map property marked databasegeneratedoption.computed
.
note needs special attention code-first (migrations). , takes performance inserts , updates because ef must read value database afterwards.
Comments
Post a Comment