score:0
void main()
{
var fruits = new list<fruit>
{
new fruit{ groceryid = 1,name = "apple", productid = 1},
new fruit{ groceryid = 1,name = "orange", productid = 2},
};
var groceries = new list<grocery>
{
new grocery { groceryid = 1, name = "fruits and vegetables" },
new grocery { groceryid = 2, name = "drinks and snacks" },
};
var joinedresults = fruits.join(groceries, // references the groceries declared above,
fruit => fruit.groceryid, // join by groceryid located on the fruit
grocery => grocery.groceryid, // join by the groceryid located on grocery
(product, grocery) => new
{
productid = product.productid,
productname = product.name,
groceryname = grocery.name
});
}
public class fruit
{
public int productid { get; set; }
public int groceryid { get; set; }
public string name { get; set; }
}
public class grocery
{
public int groceryid { get; set; }
public string name { get; set; }
}
Source: stackoverflow.com
Related Query
- How to use a dynamic LINQ join extension method for multiple conditions
- How to create a dynamic LINQ join extension method
- LINQ: How to do JOIN using the linq extension method style on multiple fields?
- LINQ extension method for multiple join with multiple GroupBy requirements
- How can i use Linq expression for Join on multiple table in EF Core 3.1
- How to use Left join linq for multiple tables
- How to Convert a LINQ Query Syntax to a Method Syntax? (with join and multiple selects) Issue: Where-no overloads for + 3 parameters
- Extension method for IQueryable left outer join using LINQ
- How to use Dynamic LINQ (System.Linq.Dynamic) for LIKE operation?
- How to use join with multiple conditions in linq-to-Nhibernate
- How to: Use async methods with LINQ custom extension method
- LINQ method syntax for multiple left join
- How to use Orderby for creating dynamic linq queries?
- Generic Extension method for LINQ JOIN using 2 columns
- How To Use C# Linq Predicate with custom Extension Method
- How-to use predicates for customer where LINQ query in Entity Framework, Extension Method "Search by Words"
- How to use Extension method inside a LINQ statement?
- Linq Extension method for Join
- Creating dynamic linq expression OData for multiple conditions for filter Contains?
- How to write SQL SELECT INNER JOIN with multiple conditions (with LIKE) query to LINQ to SQL
- How can I use Linq expression for Join with GroupBy in EF Core 3.1
- How use Reflection to condition multiple properties to check for equality in a LINQ .Where statement, depending on what class is passed?
- How to use Linq extension method with CodeFluent Entities template?
- LINQ Join on multiple columns with different record using extension method syntax
- How can i use the select method for Multiple properties with same property name
- LINQ to Entities query with join inside method for use in MVC app
- How to join multiple conditions for EF Expressions
- How to use LINQ to group by multiple conditions in a C# List?
- How to use Linq to join multiple DataTables on multiple columns containing DBNull values
- How can I use this extension method in a linq to entities query using query syntax?
More Query from same tag
- Convert Dictionary in List of of strings in C#
- Faster way to get distinct values in LINQ?
- Can not cast IEnumerable<int> from LINQ to List<int> with .ToList()?
- List : Get Next / Previous n items
- SQL to Linq Equivalent
- Cant save '\r\n' tag from Enviroment.NewLine into database
- Does Linq Contains() check for HashSet?
- How to bulk find/match and update records using LINQ?
- linq Any operator with not equal(!=)
- LINQ - Grouping objects with count of type
- Passing Entity Framework object to helper method for update
- How to generate duplicate items in a list using LINQ?
- Write Dynamic LINQ queries for sorting and projecting with EF Core
- How do you sort a parent and child collection using Linq?
- Compare two lists and find duplicate records that exist in both
- Linq wild card search mvc c#
- Does Enumerable.Where in LINQ-to-objects preserve order?
- LINQ TO DataSet: Multiple group by on a data table
- Linq SelectMany
- "IN" Operator in Linq
- Entity Framework Code First Dynamic Queries
- Taking last items from each category with Linq extension
- Confused about Linq query
- Querying many-To-many relationship with a list of parameters
- Create properties dynamically
- How to write SQL procedure to insert multiple items at a time from the list?
- How to Display result Values even null in c# Windows form with LINQ
- Get the last inserted data in Linq
- C# LINQ : Dynamically create property and values that includes sum of a value from a grouped query
- Filter key value pairs with dynamic operators