Examples on LINQ gives this
var query = context.Contacts
.Where(q => q.FirstName == "Tom");
I'm wondering what object is "query"? And also is it possible (advisable) to pass it to a method (within the same class)?
Examples on LINQ gives this
var query = context.Contacts
.Where(q => q.FirstName == "Tom");
I'm wondering what object is "query"? And also is it possible (advisable) to pass it to a method (within the same class)?
Copyright © 2021 Jogjafile Inc.
The
queryobject is most likely of typeIQueryable<Contact>. You can of course pass it to a method, whether that is in the same class or in another class does not matter.But keep in mind that LINQ does use a mechanism named "deferred execution". That means that query does not get enumerated immediately, but rather when it is needed. All the stuff you put in your query (the
Where-clause for example) gets executed then. For more information about deferred execution have a look at MSDN: Query Execution.NB: You can find out the exact type of the
queryvariable if you hover you mouse over it or thevarkeyword in Visual Studio.