Featured post
Entity Framework Inheritance -
i have looked @ several possible solutions issue did not find right one.
i need full set, is, need fetch types of base type. i.e. actionhistory type, others, inherit actionhistory base class. problem was getting entities of actionupdate type did not have actionupdatedetails collection filled.
my problem unable retrieve actionupdatedetails data within derived actionupdate class.
there 3 classes in model:
public class actionhistory { public int id {get;set;} } public class actionupdate : actionhistory { public icollection<actionupdatedetail> actionupdatedetails{get;set;} } public class actionupdatedetail { int id{get;set;} public string field{get;set;} public string value{get;set;} }
i tried implementing solution suggestion: entity framework: inheritance , include
like this:
var result = actionhistory in actionhistories select new { actionhistory, actionupdatedetails = actionhistory actionupdate ? (actionhistory actionupdate).actionupdatedetails : null };
all exception message:
unable create constant value of type 'system.collections.generic.icollection`1'. primitive types ('such int32, string, , guid') supported in context.
then tried simulate situation outside ef , worked. using poco model , have extracted involved classes separate project, filled structure sample data, , tested success, i.e. actionupdatedetails collection filled data.
any on appreciated!
n.
with regards answer, actually, correct way use oftype<t>
:
var actionupdatedetails = ctx.actionhistories .oftype<actionupdate>() .select(x => x.actionupdatedetails) .tolist();
this causes database-side filter (inner join), whereas solution performs implicit casting on items may not of type - in case null reference exception.
- Get link
- X
- Other Apps
Comments
Post a Comment