日期:2014-05-20 浏览次数:21043 次
var db = new BigDataEntities(); var g = db.Tab1 .GroupJoin(db.Tab1, a => a.id, b => b.id, (a, b) => new {a, b}) .GroupJoin(db.Tab1, c => c.a.id, d => d.id, (c, d) => new {c, d}) .Select(t => t.c.b.id); //这里如果用 t.c.a.id就没有错误,用b.id就找不到id了,什么原因,怎么解决呢。但是用join是可以的。
Group Join (back to top) Using a group join you can get all the products that match a given category bundled as a sequence. 复制代码 C# public void Linq103() { string[] categories = new string[]{ "Beverages", "Condiments", "Vegetables", "Dairy Products", "Seafood" }; List<Product> products = GetProductList(); var q = from c in categories join p in products on c equals p.Category into ps select new { Category = c, Products = ps }; foreach (var v in q) { Console.WriteLine(v.Category + ":"); foreach (var p in v.Products) { Console.WriteLine(" " + p.ProductName); } } }