IQueryable 3x slower with Contain-method vs Array

I have some records that I retrieve from the database (usually around 100-200). I also need to get the appropriate Place for each entry and fill in the Description Place in the entry. I usually did this in my .Select function, but I need to check if the Place value is null before trying to take Description . My code is as follows:

 var places = db.Places.Where(p => p.Active && p.CustomerID == cust_ID).ToArray(); foreach (var result in query) result.Description = places.Where(Place.Q.Contains(result.Latitude, result.Longitude).Compile()) .FirstOrDefault()?.Description; 

query IQueryable .

If I take up space as IQueryable or IEnumerable and remove Compile() from my expression, my code runs 3x (!!!) as slowly as when I run the code, as shown here. Does anyone have an explanation? Does places every foreach loop from the database?

(Edit since my first question was answered)

Also, is there a way to check if Place is null in my Select function (not taking the results into memory, keeping it IQueryable ), so I don't need to IQueryable over my results after?

0
c # linq entity-framework
Nov 30 '15 at 15:59
source share

No one has answered this question yet.

See similar questions:

fifty
Why is this happening? The most efficient way to get multiple objects using a primary key?

or similar:

2753
Case insensitive "Contains (string)"
1425
Calculate relative time in C #
1327
Why is it important to override GetHashCode when the Equals method is overridden?
1273
How to convert byte array to hexadecimal string and vice versa?
1106
Create a generic method restricting T to Enum
960
Return IEnumerable <T> vs IQueryable <T>
629
Dynamic LINQ OrderBy on IEnumerable <t> / IQueryable <t>
406
Using the var keyword in C #
16
Embed an IQueryable Shell to Convert Result Objects
one
Query Performance for Multiple IQueryable in .NET Core with LINQ



All Articles