WCF服务不返回虚拟属性ServiceProvider

时间:2015-06-09 18:14:05

标签: c# .net entity-framework wcf

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; }
}

尝试

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

它将ServiceProvider作为null

返回

1 个答案:

答案 0 :(得分: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