There are 3 tables: ParentCategories -> Categ开发者_如何学运维ories -> Articles.
- ParentCategory(ID, Name)
- Category(ID, parentCategoryID, Name)
- Article(ID, caregoryID, Name)
How do I select all articles with specified parentCategoryID (the table articles has only reference to categoreID, not to ParentCategoryID) using LINQ to SQL?
Something like this:
articles = (
    from a in db.Articles
    join c in db.Categories
    on ????????????
    join pc in db.ParentCategories 
    on c.ParentCategoryId equals pc.ID
    ...);
(If I understand your schema correctly) you could use an implicit join strategy like:
var articles = db.Categories
    .Where(c => c.ParentCategoryID == yourParentCategoryID)
    .SelectMany(c => c.Articles)
    .ToList();
The implicit join requires that you have Associations set up between your entities in your O/R designer.
articles = from a in db.Articles
          join c in db.Categories
          on myParentCategoryID equals c.ParentCategoryId
select a;
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论