I'm making a generic repository and FirstOrDefault is not generating the sql query that I expect.
Below you can see the relevant part. If I for example use ".Find(x => x.Id == id);" on a table using this repo the generated sql is first fetching all the rows and the doing the firstordefault operation. Where as I would have expected it to generate an where clause.
Any ideas about what Im doing wrong?
public class Repo<T> : IRepo<T> where T : class
{
protected SBContext Context { get; set; }
public Repo(SBContext context)
{
Context = context;
}
protected DbSet<T> DbSet
{
get
{
return Context.Set<T>();
}
}
public T Find(Func<T, bool> predicate)
{
return DbSet.FirstOrDefault(predicate);
}
}