include linq in c# code example
Example 1: C# linq include
//If you have a Customer model that contains a list of orders.
//You can include the orders like this
var customersWithOrders = _dbContext.Customers
.Include(c => c.Orders)
.ToList();
//Lets say those orders then contain products. You can include those like so:
var customersWithOrdersAndProducts = _dbContext.Customers
.Include(c => c.Orders)
.ThenInclude(o => o.Products)
.ToList();
Example 2: linq in c#
// Data source
string[] names = {"Bill", "Steve", "James", "Mohan" };
// LINQ Query
var myLinqQuery = from name in names
where name.Contains('a')
select name;
// Query execution
foreach(var name in myLinqQuery)
Console.Write(name + " ");