1

I have structure like this

class Lesson {
    List<Sign> signs { get; set; }
}

class Sign {
    List<Media> media { get; set;}
}

class Media {

}

Now I'm using this LINQ to get all lessons

var items = (from lesson in this.db.Lesson.Include("Sign")
                     where lesson.module_id == param
                     select lesson);

It works fine but signs list has ampty media list. I mean that attribute media in each object Sign equals null. What do I need to do to include media objects for each Sign ? Whole data is kept in database

4

1 回答 1

5

你会用db.Lesson.Include("signs.media").

to 的参数ObjectQuery<T>.Include是一个属性路径,而不仅仅是一个根属性。请注意,使用“signs.media”,您不需要单独包含“signs”:

路径是包罗万象的。例如,如果 include 调用指示 Include("Orders.OrderLines"),则不仅会包括 OrderLines,还会包括 Orders。

(顺便说一下,您应该调整您的属性名称以符合 .NET 框架约定,因此您最终会得到“Signs.Media”。)

于 2012-10-04T16:59:53.330 回答