Simplified, I have a entity, let's call it "Foo", in my database a few times.
I now want to select certain Foos based on their FooCode (a list of FooCodes is selected by the user).
Let's say I have five Foos, three of them having the FooCode "20".
I want to return a list of Foos with the FooCode "20"; the expected result is a list of Foos with the size of three.
The following LinQ-expression works totally fine, although it selects all Foos before executing the Where (please correct me if I'm wrong). So with a big amounts of Foos it's probably not the fastest solution.
// user defined list of FooCodes - now containing: "20", "20", "20"
List<string> selectedFooCodes = ...
List<Foo> = _transactionalDataAccess
.Query<Foo>(query => query)
.Where(entity => selectedFooCodes.Contains(entity.FooCode)).ToList();
I suppose a LinQ-expression as the following will select faster, because the Where is directly after the Query. Anyways, it returns a list of Foos with the size of five. As far as I understand, it should select the exactly same as the above query.
// user defined list of FooCodes - now containing: "20", "20", "20"
List<string> selectedFooCodes = ...
List<Foo> = _transactionalDataAccess
.Query<Foo>(query => query
.Where(entity => selectedFooCodes.Contains(entity.FooCode)));
Why is that? Can someone tell me what I'm missing. The above LinQ return the exactly same as:
_transactionalDataAccess
.Query<Foo>(query => query);
Why doesn't the Where make any difference?
Or is there an even faster notation I don't know about?
I'm sorry if this was asked before. I searched through the LinQ questions on StackOverflow, but haven't found a similar question. I have to admit that I decided to ask my own question, because it needs less time than reading and understanding all the existing ones.
ITransactionalDataAccesswhich narrows down toIQueryDataAccess. I'm sorry, it's a thing from our company-intern framework. It basically just represents the interface with the (Oracle) database. Hope that helps. Does it even matter? - Alex_transactionalDataAccessobject is. - Hogan