I’m working with entity framework and mysql. We created a class
public class DataBaseContext : ObjectContext, IDbContext
There is a method
public IEnumerable<T> Find<T>(Func<T, bool> whereClause) where T : class
{
return CreateObjectSet<T>().Where(whereClause);
}
Is there a way not to create ObjectSet every time when I call the method? Can I check that it is already exists?
Whooooo. That is so bad method. You are passing
Func<>, notExpression<Func<>>. It means that every time you execute your method EF will pull all records from database table mapped toTand execute your filtering in memory of your application – creating object set is the last thing you should be afraid of.Anyway creating object set should not be expensive operation and if you don’t want to create it every time you need to implement some “local caching” inside your object context instance.