This is done by setting the DeferredLoadingEnabled property of the context to false.
To then have LINQ load parent/child objects later, you must specify which relationships to load with the following:
using (ClientDBDataContext clientCtx = new ClientDBDataContext(clientDbConnStr))
{
clientCtx.DeferredLoadingEnabled = false;
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith
clientCtx.LoadOptions = loadOptions;
...query...
}
FULL EXCEPTION:
System.InvalidOperationException: There was an error generating the XML document. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'DataContext accessed after Dispose.'.
at System.Data.Linq.DataContext.GetTable(Type type)
at System.Data.Linq.CommonDataServices.GetDataMemberQuery(MetaDataMember member, Expression[] keyValues)
at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.ExecuteKeyQuery(Object[] keyValues)
at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.Execute(Object instance)
at System.Data.Linq.CommonDataServices.DeferredSourceFactory`1.DeferredSource.GetEnumerator()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at System.Data.Linq.EntityRef`1.get_Entity()
at AparcSystems.AparcDataAccess.Aparc_PdmTariff.get_Aparc_EnfArea()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write25_Aparc_PdmTariff(String n, String ns, Aparc_PdmTariff o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write57_ArrayOfAparc_PdmTariff(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.ListOfAparc_PdmTariffSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
No comments:
Post a Comment