entity framework - ObjectContext.CreateObject<T>: Create ComplexObject -
could please explain following:
i have following code creates instance of type specified:
methodinfo methodinfo = this._dbcontext.gettype().getmethod("createobject").makegenericmethod(instancetype); object invokedobject = methodinfo.invoke(this._dbcontext, null);
where _dbcontext
in entity model.
when try create instance of following class happy , works:
public partial class user : entityobject { .... }
but when try same within following class - receive error:
the member identity 'mynamespace.account' not exist in metadata collection.
public partial class account : complexobject { .... }
could please explain why i'm able create instance / object of entityobject
not complexobject
?
many thanks!!
[update]
public objectset<user> users { { if ((_users == null)) { _users = base.createobjectset<user>("users"); } return _users; } } private objectset<user> _users;
there 2 problems:
as noted in updated question,
context
doesn't contain referenceaccount
, need add before requesting (using'createobject'
method) context:public objectset<account> accounts { { if ((_accounts == null)) { _accounts = base.createobjectset<account>("accounts"); } return _accounts; } } private objectset<account> _accounts;
since
account
complextype
don't think you'll able useobjectset<>
, sincecomplextype
not haveidentity
, can used part of parententity
.
Comments
Post a Comment