c# - How to use the update method for a generic LINQ to SQL repository -
i have implemented following generic methods:
public iqueryable<t> query(expression<func<t, bool>> filter) { return context.gettable<t>().where(filter); } public virtual void update(t entity) { context.gettable<t>().attach(entity); }
i not sure how implement in consumer class? ideally, pass in userref , update user accordingly?
change to:
public iqueryable<t> query<t>(expression<func<t, bool>> filter) { return context.gettable<t>().where(filter); } public virtual void update<t>(t entity) { context.gettable<t>().attach(entity); } var user=something.query<user>(x=>x.name=="bla bla").first; user.name="alb alb"; something.update(user);
but consider avoiding writing generic repositories. don't gain them. if it's generic, exposes iqueryable, takes in expression filters, it's quite useless abstraction layer , adds complexity.
Comments
Post a Comment