c# - DbContext has been disposed when using IQueryable<> -
I have a simple query in a repository like this:
public list & lt ; MeetingVM & gt; GetMeetingsInRadius (decimal latitude, decimal longitude, int mi, int dayoffice) {var point = dbofophyte text (string format ("number ({0} {1})", longitude, latitude), 4326); (MeetingContex DB = new meeting syntax ()) using {var result = (one of DB matches where A. geo. distance (point) * 0.000621371 & lt; = mi & amp; amp; a.DayOfWeek = = (Meetings Model New MeetingVM {address = x.Address, CasoID = x.Address, day of week = x.DayOfWeek, Distance = x.Geography.Distance (point) * 0.00,06,21,371, Latitude , Enums.DayOfWeek) a) .Select (x = & gt; week of week = x.Latitude, LocationName = x.LocationName, longitude = x.Longitude, MeetingName = x.MeetingName, MeetingType = x.MeetingType, option = x Options, time = x.Tim e}). Serial (x = & gt; x.Time) .toList (); Return results; }}
I call it IQueryable
instead of
list
, and I understand what he does, to become a lazy question, and actually until then It is not executed unless it is actually called.
When I call it Text after "div class =" itemprop = "text"> In your code sample above, you are calling If you come back to IQueryable & gt; To set an example can this work and have the option to keep it open?
ToList ()
, Which gets its results from the database by using the before the end
block disposes your reference. So you should work fine. IQueryable
, then when you call, ToList ()
or FirstOrDefault ()
Or whatever else and actually execute the query (perhaps very later in your code), using the block is long since your "meeting content" is settled, so you Can not use it. Hence the exception is
Comments
Post a Comment