How to query many-to-many releationship in EF Core

后端 未结 3 1211
我寻月下人不归
我寻月下人不归 2020-12-16 13:09

I\'m using .NET Core and EF Core for a web project. I\'m struggling how to query a many-to-many releationship. This is what my models look like:

public class         


        
3条回答
  •  暖寄归人
    2020-12-16 13:23

    Extending @Richard's answer :

    I noticed in Visual Studio 2017 15.5.6 when I do following:

                return _context.Begrip
                .Include(x => x.Categories)
                    .ThenInclude(y => y.)
    

    IntelliSense at first tells me that y if of type ICollection of BegripCategory presenting methods suitable for collections what is confusing especially that when I start typing "category" (in place of "nothing typed in here yet") IntelliSense changes as if we were dealing with only a single instance instead of ICollection

    Just a tiny remark, but I hope it will help to save a few minutes time confusion.

提交回复
热议问题