I have this method, that will be called against from a WCF Client, but for my testing, I'm uisng a local "add project reference." I'm getting the error that I cannot call the DataContext after it's disposed.
public IEnumerable<Server> GetServers()
{
// initialze to null
ServersDataContext sdc = null;
try
{
// get connected
using (sdc = GetDataContext())
{
// disable this deferred loading
sdc.DeferredLoadingEnabled = false;
var relations = from svr in sdc.Servers; // complex linq here
// return
return relations;
}
}
catch (Exception ex)
{
LogError(ex, "fwizs.Internal");
throw;
}
finally
{
if (sdc != null)
{
sdc.Dispose();
}
}
}
And here is how I'm using the method, which gives this error: "Cannot access a disposed object."
if (da.GetServers()
.Select(sv => sv.ServerID == s.ServerID).Count() == 0)
{
// do work since we found it
}
Using the .Select() method on this returned IEnumerable objects trys to run back to the database to make the select. After being serialized for WCF I don't think it'll be an issue, but I would like my local tests to work.