linq中join用法
类别:编程学习 浏览量:3696
时间:2014-4-20 linq中join用法
linq中join用法一、linq中join方法原型
public static IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(
this IEnumerable<TOuter> outer,
IEnumerable<TInner> inner,
Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,
Func<TOuter, TInner, TResult> resultSelector)
二、先创建linq中join方法的实验用例
class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
public string Origin { get; set; }
}
class Order
{
public int OrderId { get; set; }
public int CustomerId { get; set; }
public List<Product> Products { get; set; }
}
static List<Customer> customers;
static List<Product> products;
static List<Order> orders;
public static void CreateEntities()
{
customers = new List<Customer>{
new Customer(){ CustomerId = 1, Name = "CA", Age=13},
new Customer(){ CustomerId = 2, Name = "CB", Age=13},
new Customer(){ CustomerId = 3, Name = "CC", Age=13},
new Customer(){ CustomerId = 4, Name = "CD", Age=13}
};
products = new List<Product>{
new Product(){ ProductId = 1, Name = "PA", Origin="P1" },
new Product(){ ProductId = 2, Name = "PB", Origin="P2" },
new Product(){ ProductId = 3, Name = "PC", Origin="P1" },
new Product(){ ProductId = 4, Name = "PD", Origin="P3" }
};
orders = new List<Order>{
new Order(){ OrderId = 1 , CustomerId =1,
Products = new List<Product>{
new Product(){ ProductId = 2, Name = "PB", Origin="P2" },
new Product(){ ProductId = 3, Name = "PC", Origin="P1" }
}},
new Order(){ OrderId = 2 , CustomerId =1,
Products = new List<Product>{
new Product(){ ProductId = 3, Name = "PC", Origin="P1" },
new Product(){ ProductId = 4, Name = "PD", Origin="P3" }
}},
new Order(){ OrderId = 3 , CustomerId =3,
Products = new List<Product>{
new Product(){ ProductId = 4, Name = "PD", Origin="P3" }
}},
new Order(){ OrderId = 4 , CustomerId =2,
Products = new List<Product>
您可能感兴趣
- Linq中的TakeWhile和SkipWhile
- linq not in 查询
- Linq中where查询
- linq 排序
- 如何查看linq生成的sql
- linq distinct去重
- linq to sql 中Concat、Union、Intersect、Except
- LINQ中Aggregate的用法
- linq中延迟执行
- linq中group by
- linq 数据类型转换
- Linq中select查询
- list使用linq排序
- linq中let
- Linq操作Datable
- LINQ TO SQL 中join
- 指天椒紫苏爆炒牛肉(指天椒紫苏爆炒牛肉)
- 谷雨前,吃牛羊肉别忘了吃河鲜,除湿还清热,加紫苏一炒特解馋(吃牛羊肉别忘了吃河鲜)
- 紫苏牛肉锅里滚一滚,香的鼻子都要掉了(紫苏牛肉锅里滚一滚)
- 每天都吃水果的好处(每天吃水果的好处与功效)
- 苹果15价格(苹果15价格512g官网)
- 春节放假几天(春节放假几天2023法定几天)