首页 > 解决方案 > .net c# EF 模型中的空嵌套对象

问题描述

我不明白为什么嵌套对象不为空......

var client = db.Clients.Find(id);
if(client != null) {
    client.someNestedObject = null;

    var x = client.someNestedObject;
    //here, x is NOT NULL!!!??? (its a proxy but not null)
}

嵌套对象模型:

   public int id { get; set; }
   public virtual Client client { get; set; }

客户型号:

   public int id { get; set; }
   public string client_name { get; set; }
   [ForeignKey("someNestedObject")]
   public int id_nested { get; set; }

   public virtual NestedObject someNestedObject { get; set; }

标签: .netentity-framework

解决方案


默认情况下不加载相关实体,请参阅EF6EF Core


推荐阅读