1

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)?

Spontifixus
  • 6,570
  • 9
  • 45
  • 63
NotMe
  • 745
  • 2
  • 7
  • 26

1 Answers1

2

The query object is most likely of type IQueryable<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 query variable if you hover you mouse over it or the var keyword in Visual Studio.

Spontifixus
  • 6,570
  • 9
  • 45
  • 63