Pertinent Observer
Pertinent Observer

Reputation: 311

how to call grand child tables in the Queryable include statement

Suppose I have the following three tables

There is 1 to many relationship between the tables as follows:

I am using Entity framework to query the table and the programming is in C#. Suppose, I need all the columns in A, I do the following:

var query = _context.A; query.where( <where clause> )

If I need to include the columns of B to prevent lazy loading,

query.Include ( s => s.B );

The question is, how do I include the columns of C to prevent lazy loading? I am looking for something like:

query.Include ( s => s.B.C ) ( This does not work because of the 1 to many relationship between the tables )

Upvotes: 0

Views: 68

Answers (1)

ocuenca
ocuenca

Reputation: 39326

You can load your third level as part of your query as I show below:

query.Include (s => s.B.Select(b=>b.C));

If you go to Remarks section in this msdn page, you will find several examples how to include different levels using Include extension method.

Upvotes: 1

Related Questions