开发者

restrict num of items loaded in navigation property

I have the following query in Linq:

var query = from question in context.Questions.Include("QAnswers")
            join answer in context.Answers
                on question.id equals answer.qst
            where answer.user == param_userID
            select question;    
return query.toList();

The problem is that it doesn't load the "QAnswers" navigation property at all. Is there any way in Entity Framework to return the entity and restricted result set in its navigation property?

Ps. I'm us开发者_运维百科ing EF4 if it's important


If I understood it correctly, this should be enough:

context.Questions.Include("QAnswers").Where(q => q.QAnswers.Any(a => a.user == param_userID));

These are questions where specific user answered. There is no need for joins.

EDIT

context.Questions.Where(q => q.QAnswers.Any(a => a.user == param_userID)).Select(q => new { Question = q, Answers = q.QAnswers.Where(a => a.user == param_userID) }).ToList();

This will return question and only specific user's answers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜