views:

33

answers:

1

Hi folks,

i've got a really simple linq to entites statement :-

var query = (from q in Users.Include("UserHistory")
            select q).Take(20);

works great ... except that, for each user .. the history can be n+1. Some users have 100's of UserHistory records.

So, can I restrict the the number of UserHistory records to .. 10 or 5 or whatever?

Do I need to use projections for this? Can it be done without projections?

A: 

You can't do this by using the include, but you can try this:

var query =
    from user in Users
    select new
    {
        user, 
        history = user.UserHistory.Take(20) 
    };

I'm not sure whether EF is able to create one single SQL query of of it.

Steven
Yep - Alex James (of MS ADO.NET / Linq-To-Sql / EF / OData fame) confirmed this on twitter.
Pure.Krome