Reputation: 135
is there a way to make this generic
Context.SalesEntity.Where(t=>t.id==3).Delete();
something like
private void DoWork<T>(Expression<Func<T, bool>> predicate)
{
Context.T.Where(predicate).Delete();
}
I have already tried the predicate bit seems to work ok. but I have no idea how to do the context.entity bit generically.
Upvotes: 2
Views: 479
Reputation: 1533
private void DoWork<T>(Expression<Func<T, bool>> predicate)
{
Context.Set<T>().Where(predicate).Delete();
}
Upvotes: 2
Reputation: 39898
You can use the Context.Set<T>
method. This returns a DbSet<T>
of the specified type.
Upvotes: 4