开发者

Conditional Includes

开发者 https://www.devze.com 2023-03-04 20:49 出处:网络
I would like to know how I can change this query: events = _database.Events .Include(\"Contacts\") .ToList();

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

精彩评论

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

关注公众号