I see several design errors and problems in the code.
Firstly, the custom method is "Everything." A line of code that selects all notes in notesQuery does nothing.
var notesQuery = from note in setOfNotes select note;
Remember that 'setOfNotes' is already an IQueryable of type Note. The statement effectively says: "Select all notes to select all notes." LINQ will completely remove this statement from the inside (with little performance), so it can be safely removed from your code.
Try changing the function to:
public IQueryable<NOTE> All(Expression<Func<NOTE, bool>> predicate = null) { var setOfNotes = GetDbSet<NOTE>(); return (predicate == null) ? setOfNotes : setOfNotes.Where(predicate); }
There are big fundamental problems in design. For .NET collections, the All method is used to determine whether the predicate is true for each element in the collection. This does not mean "return all items." Of course, you create your own repository, but naming conflicts with standard use of .NET. I would actually suggest you completely get rid of your custom repository.
LINQ is a "language integrated query" - the whole point is to integrate it with your code. Wrapping another layer around it is pointless and contradicts intuition. DbSet implements the IQueryable interface - exposes this directly and requests it in your code. This allows LINQ to cache queries more efficiently and avoid redundancy. IQueryable already has a repository, it makes no sense to create another. You simply threw out LINQ power and returned to the days of stored procedures.
If you have complex queries used in many places, just write an extension method on IQueryable that returns another IQueryable. Then you can GetDbSet (). SliceAndDice ()!
Returning to the original problem, you can mix assignment with comparison. The code you included included:
var notes = repository.All(n => n.NOTENUMBER = notenumber).ToList();
This is not true, its attempt to assign "notenumber" to the n.NOTENUMBER property, not an equality check. Perhaps it was a typo in the column. Try instead:
var notes = repository.All(n => n.NOTENUMBER == notenumber).ToList();
Or even better:
var notes = GetDbSet<NOTE>().Where(n => n.NOTENUMBER == notenumber).ToList();
I suspect that the equality error was just a typo, but the problem is probably that you "overlay" the custom repository on the IQueryable repository and pass the expression between them and discard the EF's ability to cache correctly.