C# JsonResult禁用延迟加载
我在DbContext中禁用了延迟加载,如下所示:C# JsonResult禁用延迟加载,c#,entity-framework,lazy-loading,C#,Entity Framework,Lazy Loading,我在DbContext中禁用了延迟加载,如下所示: public partial class SkipstoneContext : DbContext { static SkipstoneContext() { Database.SetInitializer<SkipstoneContext>(null); // Exsting database, do nothing } public SkipstoneContext()
public partial class SkipstoneContext : DbContext
{
static SkipstoneContext()
{
Database.SetInitializer<SkipstoneContext>(null); // Exsting database, do nothing
}
public SkipstoneContext()
: base("DefaultConnection")
{
}
// ...
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.Configuration.LazyLoadingEnabled = false; // Disable Lazy Loading
// ...
}
}
它试图通过延迟加载加载所有属性。
我的用户类如下所示:
public partial class User : IdentityUser
{
public string CompanyId { get; set; }
public string CreatedById { get; set; }
public string ModifiedById { get; set; }
public System.DateTime DateCreated { get; set; }
public Nullable<System.DateTime> DateModified { get; set; }
public System.DateTime LastLoginDate { get; set; }
public string Title { get; set; }
public string Forename { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public string JobTitle { get; set; }
public string Telephone { get; set; }
public string Mobile { get; set; }
public string Photo { get; set; }
public string LinkedIn { get; set; }
public string Twitter { get; set; }
public string Facebook { get; set; }
public string Google { get; set; }
public string Bio { get; set; }
public string CompanyName { get; set; }
public string CredentialId { get; set; }
public bool IsLockedOut { get; set; }
public bool IsApproved { get; set; }
public bool CanEditOwn { get; set; }
public bool CanEdit { get; set; }
public bool CanDownload { get; set; }
public bool RequiresApproval { get; set; }
public bool CanApprove { get; set; }
public bool CanSync { get; set; }
public bool AgreedTerms { get; set; }
public bool Deleted { get; set; }
public Company Company { get; set; }
public User CreatedBy { get; set; }
public User ModifiedBy { get; set; }
public ICollection<Asset> Assets { get; set; }
public ICollection<Category> Categories { get; set; }
public ICollection<Collection> Collections { get; set; }
public ICollection<Comment> Comments { get; set; }
public ICollection<LocalIntegration> LocalIntegrations { get; set; }
public ICollection<Page> Pages { get; set; }
public ICollection<Rating> Ratings { get; set; }
public ICollection<Theme> Themes { get; set; }
public ICollection<Group> MemberOf { get; set; }
public ICollection<Category> ForbiddenCategories { get; set; }
public ICollection<Page> ForbiddenPages { get; set; }
}
公共部分类用户:IdentityUser
{
公共字符串CompanyId{get;set;}
公共字符串CreatedById{get;set;}
公共字符串ModifiedById{get;set;}
public System.DateTime DateCreated{get;set;}
公共可为空的DateModified{get;set;}
public System.DateTime lastloginandate{get;set;}
公共字符串标题{get;set;}
公共字符串名{get;set;}
公共字符串姓氏{get;set;}
公共字符串电子邮件{get;set;}
公共字符串JobTitle{get;set;}
公用字符串电话{get;set;}
公共字符串Mobile{get;set;}
公共字符串Photo{get;set;}
公共字符串LinkedIn{get;set;}
公共字符串Twitter{get;set;}
公共字符串{get;set;}
公共字符串Google{get;set;}
公共字符串Bio{get;set;}
公共字符串CompanyName{get;set;}
公共字符串CredentialId{get;set;}
公共bool IsLockedOut{get;set;}
公共布尔值已批准{get;set;}
公共bool CanEditOwn{get;set;}
公共bool CanEdit{get;set;}
公共bool CanDownload{get;set;}
公共布尔要求重新批准{get;set;}
公共bool可以批准{get;set;}
公共bool CanSync{get;set;}
公共bool agreedtterms{get;set;}
公共bool已删除{get;set;}
上市公司{get;set;}
公共用户CreatedBy{get;set;}
公共用户通过{get;set;}修改
公共ICollection资产{get;set;}
公共ICollection类别{get;set;}
公共ICollection集合{get;set;}
公共ICollection注释{get;set;}
公共ICollection LocalIntegrations{get;set;}
公共ICollection页{get;set;}
公共ICollection分级{get;set;}
公共ICollection主题{get;set;}
{get;set;}的公共ICollection成员
公共ICollection禁止类别{get;set;}
公共ICollection禁止页面{get;set;}
}
有人知道阻止JsonResult尝试执行此操作的方法吗?您必须移动此代码
base.Configuration.LazyLoadingEnabled=false
进入SkipstoneContext
构造函数,全局禁用上下文上的延迟加载。像这样:
public SkipstoneContext()
: base("DefaultConnection")
{
base.Configuration.LazyLoadingEnabled = false;
}
什么是
service.GetAll(“MemberOf”)代码>返回?
public SkipstoneContext()
: base("DefaultConnection")
{
base.Configuration.LazyLoadingEnabled = false;
}