How to do joins in LINQ on multiple fields in single join

前端 未结 13 1925
小鲜肉
小鲜肉 2020-11-22 17:02

I need to do a LINQ2DataSet query that does a join on more than one field (as

var result = from x in entity
join y in entity2 
       on x.field1 = y.field1          


        
13条回答
  •  北海茫月
    2020-11-22 17:55

    As a full method chain that would look like this:

    lista.SelectMany(a => listb.Where(xi => b.Id == a.Id && b.Total != a.Total),
                    (a, b) => new ResultItem
                    {
                        Id = a.Id,
                        ATotal = a.Total,
                        BTotal = b.Total
                    }).ToList();
    

提交回复
热议问题