2015-02-24 93 views
0

我正在使用LoadProperty來使用QueryOperationResponse類加載相關實體的屬性。如何使用WCF中的LoadProperty方法跟蹤相關實體

下面是代碼:作業實體的

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

這裏部位相關的實體,它也是這方面的一個屬性。 如果我使用上面的代碼,我得到一個異常「上下文不是當前跟蹤實體」。

任何人都可以幫助我嗎?

Manoj

回答

0

我得到了同樣的錯誤。我通過重用相同的上下文對象解決了這個問題。

實施例:

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

相關問題