c# - Delaying LINQ to SQL Select Query Execution -


I am creating an asp.net mVC site that uses SQL from LINQ.

In my search the method that has some necessary and some optional parameters, I want to create a LINQ query while testing the existence of those optional parameters .


Here's what I think:

 using  (var db = new dbDintIntext) (IQueryable & lt; Listing & gt; Query = null; // Required parameter query = db.Listings.Where (l = & gt; L.Lat> gt; = form.bounds.extent1.latitude & amp; l.Lat & lt; = form.bounds.extent2.latitude) handles ; // Optional parameters handle if (numStars! = Null) query = query.Where (l = & gt; l.Stars == (int) numStars); // Other parameters ... // execution query (what happens here?) Var results = query. Toolist (); // Check the process ...  

Is this implementation "bundle" to where section and then perform bundle query ? If not, how should I implement this feature?

Besides, is there anything else that I can improve?

Thanks in advance.

Yes, the query will be executed only once toList () It is said that if you follow this method and are using anonymous types, then order-by () back instead of iOrderedQueryable IQueryable

Keep in mind that you are only able to recycle on IQueryable , you do not need to call toList to access the data.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -