0

How to convert LINQ query to Lambda

What does this command look like in Lambda

The shopping table has join to product table

var result = (from a in db.Tbl_ShoppingCart
              group a.Productid by a.Tbl_Product into g
              orderby g.Count() descending
              select g.Key).Take(8).ToList();
  • [Linq 101 Samples, Lambda-Style](http://linq101.nilzorblog.com/linq101-lambda.php). In particular, take note of the GroupBy method, which returns an `IGrouping` instead of an `IEnumerable`. [This example](http://linq101.nilzorblog.com/grouping-operators.php#groupby-simple-1) shows how GroupBy works, lambda-style. [This post](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable?view=netframework-4.8) explains how each Linq method works. – Robert Harvey Mar 29 '20 at 20:12
  • You could use [LINQPad](https://www.linqpad.net/). Take your query above and run it. LINQPad has a tab to show you the lambda equivalent. – BrianM Mar 29 '20 at 20:16
  • FYI that's query syntax and I believe you're asking to translate it to method syntax. – juharr Mar 29 '20 at 21:03

0 Answers0