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
答案 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