Entityframework Join using join method and lambdas

前端 未结 3 1580
无人及你
无人及你 2020-12-04 12:50

It seems there are different ways to do joins using linq. One is more straightforward and involves just joining tables like this:

var found = from c in s.cat         


        
3条回答
  •  没有蜡笔的小新
    2020-12-04 13:41

    If you have configured navigation property 1-n I would recommend you to use:

    var query = db.Categories                                  // source
       .SelectMany(c=>c.CategoryMaps,                          // join
          (c, cm) => new { Category = c, CategoryMaps = cm })  // project result
       .Select(x => x.Category);                               // select result
    

    Much more clearer to me and looks better with multiple nested joins.

提交回复
热议问题