score:3
Accepted answer
if you order does not refer back to a customer, the trick is to first create a dataset which keeps the customers and orders linked together:
customers
.selectmany(c => c.orders.select(o => new {
cust = c,
ord = o
}))
then on this customerorder
(co
) you can apply your join:
...
.join(products,
co => co.ord.productid,
prod => prod.productid,
(co,prod) => new {
co.cust.name,
co.ord.productid,
orderamount = ord.quantity * prod.price});
Source: stackoverflow.com
Related Query
- How to write this code using the Linq Extension Method-Syntax?
- LINQ: How to do JOIN using the linq extension method style on multiple fields?
- How can I write the following code more elegantly using LINQ query syntax?
- Why the extension method of where for LINQ in this code would print out a single number while it shouldn't print anything at all?
- How would I achieve a unique result using the Linq method syntax
- Write LINQ query without select or group clause using extension method syntax
- How can I use this extension method in a linq to entities query using query syntax?
- How can i fix this method using Linq so that the test (which should already work because the result is correct) works?
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Using LINQ extension method syntax on a MatchCollection
- How to Convert LINQ Comprehension Query Syntax to Method Syntax using Lambda
- How do I count the number of child collection's items using LINQ Method Syntax?
- How to get the sum of list of shorts using the extension method Sum()?
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- How can I simplify Linq extension method invokation using reflection?
- How do I pass a method as the parameter of another method using linq expressions
- In LINQ, how do I modify an existing LINQ extension method to add a "By" selector, i.e. add Func<T> TResult to the function signature?
- Problems trying to use GroupBy with multiple properties using the LINQ Method Syntax
- How to convert this Linq query syntax to method syntax?
- How to get the key when using linq Max() method
- How to apply a function to every element in a list using Linq in C# like the method reduce() in python?
- How do I get the first value from this collection using Linq to Entities?
- How to write this functionality as a generic extension method in C#?
- How to convert this LINQ query syntax that connects two objects to method syntax?
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- How to do a subselect using linq method syntax
- Need Left Outer Join in LINQ using Extension Method /Query Syntax
- How do I modify this linq query using the lambda operator?
- How would you write this C# code (that uses the yield keyword) succinctly in Ruby?
- How to simplify the code Using LINQ
More Query from same tag
- "unrecognized expression node array index linq" exception in LINQ to SQL
- Python: LINQ capable class supporting simultaneously laziness and fluent design
- How to calculate multiple averages in one query in linq to entities
- Turn this code into LINQ
- LINQ to SQL debug visualizer for VS 2012?
- Can I use the orderby linq keyword with a comparer?
- Will eager loading a Linq to Entity query before rendering my view slow things down?
- How to concatenate two columns in linq to sql query's select projection
- get values from a nested dictionary using lambda values of the dictionary are ArrayList of ArrayList
- Linq query to filter out list of list without using Remove
- Condittionaly enable/disable automatic formatting for children
- Enumerating IEnumerable in EF6 in debugger issues "Children could not be evaluated" error
- Sum method return long value
- How and where to use AddRange() method
- Index of Linq Error
- Querying complex nested object in cosmosdb using sql Api
- Custom Func<> delegate inside Linq where clause
- Unable to display LINQ query output values from controller to view
- Categorize duplicate elements under same key
- How to select *some* items with LINQ?
- Simple LINQ Query with LINQ to SQL, think I'm doing something wrong
- Linq Select and Aggregate within a single iteration
- How to do this query in Linq?
- GroupBy in List of items using LINQ
- How to get the distinct record name and its each record count to bind to gridview in C# using Linq from SQL Server
- Linq select parent/parents record with matching child items
- how do I pass null to int column in linq
- Unable to create instance of MyEntities
- How to get NULL from LINQ When no value found in the joining tables
- Left join multiple tables using lambda expression