Azure 移动服务表控制器 updateAsync 以内存不足异常结束

Azure Mobile Services Tablecontroller updateAsync ends up in out of memory exception

当我 运行 一个运行 updateAsync(id,patch) 的补丁方法时,我最终陷入了我认为的无限引用循环,然后随着服务器因内存不足异常而崩溃而停止。

所以我有模型

  public class User : EntityData
{
    public string Username { get; set; }
    public virtual ICollection<Bar> Bars { get; set; }
    public virtual ICollection<Foo> Foos { get; set; }
}

public class Bar: EntityData
{
    public string FooId { get; set; }
    public string UserId { get; set; }
    public enum enumStatus { get; set; }
    public virtual Foo Foo { get; set; }
    public virtual User User { get; set; }
} 

public class Foo: EntityData
{
   public string Title { get; set; }
   public string UserId { get; set; }
   public virtual ICollection<Bar> Bars { get; set; }
   public virtual User User { get; set; }
}

tablecontroller 补丁操作如下所示

public Task<Bar> PatchInvited(string id, Delta<Bar> patch)
{
     return UpdateAsync(id, patch);
}

所以我尝试修补 Bars enumstatus 然后感觉它开始循环遍历所有相关实体并开始更新它们。 我该如何解决这个问题?也许我应该重新考虑我的遗产

更新 1:经过进一步调查,它似乎在我没有要求的情况下加载了所有相关实体。为什么会这样?

尽管延迟加载很有趣,但也因此可能很危险。我个人更喜欢禁用延迟加载并使用 IQueryable<T>.Include 方法只包含与查询相关的相关实体,否则你可能会不小心拉取整个数据库。您可以在 MobileServiceContext 构造函数中关闭延迟加载:

    public MobileServiceContext() : base(connectionStringName)
    {
        Configuration.LazyLoadingEnabled = false;
        Configuration.ProxyCreationEnabled = false;
    }

您可以找到一个使用 IQueryable<T>.Include() 完成预先加载的好例子 here

希望这就是您要找的!