Reputation: 63710
EF6 provides generic ways to control DB state through DbContext.Entry(object).XXX
as opposed to DbContext.Objects.XXX
Is there a way to do this generically to test if an object exists? All I've come across would be calling DbContext.Objects.Any(...)
and since my code-base is generic across about 6 different types this is a shame.
Upvotes: 2
Views: 86
Reputation: 39326
You could use Set<TEntity>
generic method:
public bool Exist<T>(Expression<Func<T,bool>> condition)
{
return context.Set<T>().Any(condition);
}
Upvotes: 2