2015-06-09 41 views
1
public class Account 
{ 
    [DataMember] 
    public int AccountId { get; set; } 
    [DataMember] 
    public string Email { get; set; } 
    [DataMember] 
    public string Password { get; set; } 
    [DataMember] 
    public string ConfirmPassword { get; set; } 

    [ForeignKey("ServiceProvider")] 
    [DataMember] 
    public int ServiceProviderId { get; set; } 
    [DataMember] 
    public virtual ServiceProvider ServiceProvider { get; set; } 
} 

WCF服務沒有返回虛擬財產的ServiceProvider

this.context.Configuration.LazyLoadingEnabled = false; 
this.context.Configuration.ProxyCreationEnabled = false; 

試過返回ServiceProvider作爲null

+0

當this.context.Configuration.LazyLoadingEnabled = true時,它返回錯誤; // this.context.Configuration.ProxyCreationEnabled = true;底層連接已關閉:接收時發生意外錯誤。 – user3906377

+0

也在這裏發佈您的'ServiceProvider'實體。 –

+0

如果你正在將EntityFramework展示給WCF,你應該着眼於使用[WCF DataServices](https://msdn.microsoft.com/en-us/library/dd673932(v = vs.110).aspx),它是特別的專爲處理類似你遇到的問題而設計。 –

回答

1

使用預先加載與包括法:

using System.Data.Entity; 
//... 
context.Accounts.Include(x => x.ServiceProvider).Where(...) 

請參見本主題澄清: What are the downsides to turning off ProxyCreationEnabled for CTP5 of EF code first

+0

我從DB數據被成功來服務的方法,但不能將它發送給客戶端 – user3906377

+0

你可以有序列化的問題,客戶端\服務器或客戶端模式的問題misconficuration。確保無處不在[DataContract]。檢查沒有提供者的賬戶是否工作。檢查客戶端模型(帳戶有提供者成員)。 – FireAlkazar

+0

是它的工作fyn沒有提供商,我知道它的序列化問題,但什麼問題:-)我已經正確使用DataContract和DataMember,當我使用懶加載= false,serviceprovider爲空,但它到達客戶端 – user3906377