This project is read-only.


Dec 4, 2013 at 1:18 PM

I made a simple repository.
The base class is DbEntitySessionBase.

I implemented a method to query on item.
    public virtual TEntity FirstOrDefault(Func<TEntity, bool> predicate)
        return this.GetTable<TEntity>().FirstOrDefault(predicate);
The problem is that in the OutputWindow (with the DebuggerWriter) I can see that a complete select statement without a where condition is created. (SELECT FIELDA, FIELDB... FROM TABLE)

Is it possible to generate a select statement with a where condition?

Thank you,
Dec 4, 2013 at 1:41 PM
From what I remember, the FirstOrDefault(predicate) method isn’t supported. In fact, I thought that it used to throw a NotSupportedException but apparently not based on your usage. You could just rewrite the statement to use Where(predicate).FirstOrDefault().

public virtual TEntity FirstOrDefault(Func predicate)
return this.GetTable().Where(predicate). FirstOrDefault();