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?
c # linq entity-framework
Alexander Derck Nov 30 '15 at 15:59 2015-11-30 15:59
source share