c# - How to get entity type in EntityFramework when TPH inheritance model is used -
we use table per hierarchy (tph) store inherited entities in ef6.1 (code first). internally ef uses column discriminator keep type of entity.
i can retrieve specific entity types using oftype<>()
extension. can check type of entity using is
operator. cannot figure out how retrieve entity type itself. have hierarchy of several entities , need retrieve few properties (i don't want load whole entities) need select entity type. current solution below. suboptimal. there way how type in better way?
return dbset.where(o => o.id == id) .selectmany(o => o.basetransactions .where(o => !(o x00transaction))) .select(o => new transactioninfodto { transactionid = o.id, amount = o.amount, transactiontype = o x01transaction ? loandetailtransactiontype.x01 : o x02transaction ? loandetailtransactiontype.x02 : o x03transaction ? loandetailtransactiontype.x03 : o x04transaction ? loandetailtransactiontype.x04 : o x05transaction ? loandetailtransactiontype.x05 : loandetailtransactiontype.x06, });
Comments
Post a Comment