如何使用WCF中的LoadProperty方法跟踪相关实体

问题描述:

我正在使用LoadProperty来使用QueryOperationResponse类加载相关实体的属性。如何使用WCF中的LoadProperty方法跟踪相关实体

下面是代码:作业实体的

QueryOperationResponse<T> response= _context.LoadProperty(job, "Parts", token) as QueryOperationResponse<T>; 

这里部位相关的实体,它也是这方面的一个属性。 如果我使用上面的代码,我得到一个异常“上下文不是当前跟踪实体”。

任何人都可以帮助我吗?

Manoj

我得到了同样的错误。我通过重用相同的上下文对象解决了这个问题。

实施例:

MyContext proxy = new MyContext(new Uri("http://localhost:62717/MyService.svc/", UriKind.Absolute)); 
var MyEntity = proxy.MyEntity.Where(x=>x.id = 1).First(); 
// ... 
// Later in the code: 
// A new proxy is created. This will cause the failure in the next line. 
proxy = new MyContext(new Uri("http://localhost:62717/MyService.svc/", UriKind.Absolute)); 
proxy.LoadProperty(MyEntity, "RelatedEntity"); 
// Make sure you reuse the same proxy as the one you loaded your MyEntity object. 
+0

感谢您的溶液。我能够使用相同的上下文对象解决问题。再次感谢您的答复。 – 2015-05-13 11:31:57