working ef6, in generic method, trying set property values so:
protected void myfunc<t>(t entity, params expression<func<t, dynamic>>[] properiestocopy) t: class { foreach (var propertyentry in properiestocopy) { context.entry(_entitycopy).property(propertyentry ).currentvalue = context.entry(entity).property(propertyentry).currentvalue; } } now, use same function reference types of entity, have use dbentityentry.reference function.
how can know whether lambda expression (named propertyentry above) referes dbpropertyentry or dbreferenceentry? or can function perform same action in better way?
i found answer, had use dbentityentry.member function, work scalar types, reference types , collections. however, works string parameter: took method tryparsepath entity framework source code converts lambda path string path.
then do:
string path; foreach (var memberentry in memberstocopy) { if (!utils.tryparsepath(memberentry .body, out path)) { throw new argumentexception("include path not valid", "path"); } context.entry(_entitycopy).member(path).currentvalue = context.entry(entity).member(path).currentvalue; }
Comments
Post a Comment