c# - update generic entity in linq to object -
i have function written in linq sql
public static bool update(system.linq.expressions.expression<func<t,bool>> predicate,action<t> setter) { try { context mycontext = new context (); t updateobject; updateobject = mycontext.gettable<t>().where(predicate).first(); setter(updateobject); nhagodb.submitchanges(); return true; } catch (exception ex) { return false; } } but dont know how write in linq object, there's no method gettable<t>().where(predicate).first();
please many :)
i don't see such method necessary in linq objects. code can work itself. e.g.
var myobject = mylist.first(x => x.something); myobject.updatesomething(newvalue); // or just: mylist.first(x => x.something).updatesomething(newvalue); if did want method this, called like:
mylist.update(x => x.something, x => x.updatesomething(newvalue)); the former shorter, clearer (imo), , faster latter.
Comments
Post a Comment