The condition is included in linq for objects

I have this basic table structure:

Messages

Postxtags

Posttags

There is a 1-n relationship between posts, PostXTags and between PostTags, PostXTags

I need to get all posts with their tags.

PostTags has a type field, and I want a filter on it. Each condition also encounters this error:

The Include path expression must specify the navigation property defined in the type. Use dashed paths for referenced navigation properties and the Select statement for navigation properties for the collection. Parameter Name: Path

Public IQueryable<Post> GetPosts() { return from p in _db.Posts select p; } var posts = GetPosts().Include(p => p.PostXTags.Select(pxt => pxt.PostTag).Where(pt=>pt.Type == 2)).ToList(); 
+4
source share
1 answer

I think you are trying to achieve

 var posts = _db.Posts.Include("PostXTags.PostTag"). Where(p => p.PostXTags.Any( pxt => pxt.PostTags.Any( pt => pt.Type == 2 ) )); 
+6
source

Source: https://habr.com/ru/post/1403401/


All Articles