Why does Entity Framework return null List<> instead of empty ones?

前端 未结 3 1827
终归单人心
终归单人心 2021-01-01 09:35

I\'m pretty new in the ASP .NET MVC world. Maybe, that\'s the reason I can\'t explain to myself the cause of what is, for me, an annoying problem.

I have one class w

3条回答
  •  被撕碎了的回忆
    2021-01-01 10:11

    Make the otherClasses collection virtual. This will enable EF to lazy load the collection.

    class MyClass{
        public virtual List otherClasses {get;set;}
    }
    

    Otherwise use eager loading with Include method.

    context.myClass.Include(m => m.otherClasses).SingleOrDefault(m => m.Id == foo);
    

提交回复
热议问题