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 ; Tried to change to return 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 IQueryable & gt; To set an example can this work and have the option to keep it open?

Text after "div class =" itemprop = "text">

In your code sample above, you are calling ToList () , Which gets its results from the database by using the before the end block disposes your reference. So you should work fine.

If you come back to 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

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -