Reputation: 591
As you know, in EF Core 5.0 you can have relationships without explicitly mapping the tables. The question is: since you don't have the mapping classes anymore, how can you actually join/filter them?
Take the snipped as example:
public class Product
{
...
public IList<Category> Categories {get;set;}
}
public class Category
{
...
public IList<Product> Products {get;set;}
}
This code in EF 5.0 is (correctly) generating a mapping table named ProductCategory automatically with the proper FK in the database, linking ProductId and CategoryId together. This table mapping has no equivalent class in the source code.
Now my problem is, how can I filter values for those two tables without the mapping class in the code? For example, how to represent the following hypothetical query:
SELECT ALL PRODUCTS JOIN CATEGORIES WHERE [HOW TO LINK THEM?] PRODUCT ISAVAILABLE AND CATEGORY BELONGS TO ELETROCNICS
Thanks in advance.
Upvotes: 2
Views: 797
Reputation: 27282
I hope my telepathy is good enough.
var query =
from p in ctx.Products
where p.Categories.Any(c => c.Name == "Electorics")
select p;
Upvotes: 1