开发者

Conditional Includes

I would like to know how I can change this query:

events = _database.Events
         .Include("Contacts")
         .ToList();

To inclu开发者_Python百科de only contacts having their property "Type" set to "event".

I'm using EntityFramework, _database is its context.


Firstly, it's worth understanding that the code you posted doesn't include a lambda expression at all. "Query not in query expression syntax" isn't the same as "lambda expression".

I suspect it would be a bad idea to return event objects with a partially-filled entity reference set. However, you could do this:

_database.Events
         .Select(e => new { Event = e,
                            EventContacts e.Contacts
                                           .Where(c => c.Type == "event") });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜