C# Linq Examples

Date: 2016-10-25

Join:

var data = db.Product
                            .Join(db.ArtikelGroep,
                                a => a.ProductId,
                                b => b.HoofdGroepId,
                                (a, b) => new { a, b })
                            .Where(p => p.a.ProductId < 25).OrderBy(p => p.a.Name);
                    var records = data.ToList();

 

GroupBy:

var results = persons.GroupBy( p => new { p.Id, p.Name }, 
                               p => p.car,
                               (key, g) => new { 
                                      PersonId = key, 
                                      Cars = g.ToList() 
                                  }
                              );
5320cookie-checkC# Linq Examples