我现在的笨方法是这样: var k = dc.Table .Where(x => x.DepartmentUsers.Any(v => v.UserName.Contains("芳")));
foreach(var t in k) { Console.WriteLine(t.DepartmentName); var tmp = t.DepartmentUsers.Where(x => x.UserName.Contains("芳")); foreach (var c in tmp) Console.WriteLine("<" + c.UserName + ">"); Console.WriteLine(Environment.NewLine); }
Console.Read();
请问如何把他修改的效率更高一点呢?
------解决方案--------------------
精简一下:
var queryResult = departmentList.Join(userList.Where(U => U.lastName.Equals("Li")), department => department.id, UR => UR.id, (department, UR) => new { departmentName = department.name, userName = (UR.lastName + UR.firstName)}).GroupBy(R => R.departmentName).ToList();