如何将linq left join 的写法转换成 limq left join lambad的写法var query = from person in people join pet in pets on person equals pet.Owner into gj from subpet in gj.DefaultIfEmpty() select new { person.FirstName,PetName = (subpet == null
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 13:03:40
如何将linq left join 的写法转换成 limq left join lambad的写法var query = from person in people join pet in pets on person equals pet.Owner into gj from subpet in gj.DefaultIfEmpty() select new { person.FirstName,PetName = (subpet == null
如何将linq left join 的写法转换成 limq left join lambad的写法
var query = from person in people join pet in pets on person equals pet.Owner into gj from subpet in gj.DefaultIfEmpty() select new { person.FirstName,PetName = (subpet == null String.Empty :subpet.Name) };
以上是在msdn社区上搜所得例子
但是我不习惯这样写 我想写成
var query = people.join(pest,pets=>pets.owner,person=>person.)这样的形式
IList StuList = new List();
#region Addstudents
Student Me = new Student();
Me.Name = "haojun";
Me.InTime = DateTime.Now;
Me.ClassID = 1;
Student Her = new Student();
Her.ClassID = 1;
Her.Gender = 2;
Her.Name = "ruegy";
Student Him = new Student();
Him.ClassID = 2;
Him.Name = "jim";
StuList.Add(Me);
StuList.Add(Her);
StuList.Add(Him);
#endregion
IList ClassList = new List();
#region AddClass
MyClass One = new MyClass();
One.ClassID = 1;
One.ClassName = "x-man";
MyClass Tow = new MyClass();
Tow.ClassID = 3;
Tow.ClassName = "KingKong";
ClassList.Add(One);
ClassList.Add(Tow);
#endregion
如何将linq left join 的写法转换成 limq left join lambad的写法var query = from person in people join pet in pets on person equals pet.Owner into gj from subpet in gj.DefaultIfEmpty() select new { person.FirstName,PetName = (subpet == null
LZ没看MSDN啊,“左外部联接操作没有专用的标准查询运算符,但可以使用 GroupJoin 方法执行此操作.”
var query =
people.GroupJoin(pets,
person => person,
pet => pet.Owner,
(person,petCollection) =>
new
{
OwnerName = person.Name,
Pets = petCollection.Select(pet => pet.Name)
});
这样的