如何将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/09/06 13:11:31
![如何将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](/uploads/image/z/11244650-50-0.jpg?t=%E5%A6%82%E4%BD%95%E5%B0%86linq+left+join+%E7%9A%84%E5%86%99%E6%B3%95%E8%BD%AC%E6%8D%A2%E6%88%90+limq+left+join+lambad%E7%9A%84%E5%86%99%E6%B3%95var+query+%3D+from+person+in+people+join+pet+in+pets+on+person+equals+pet.Owner+into+gj+from+subpet+in+gj.DefaultIfEmpty%28%29+select+new+%7B+person.FirstName%2CPetName+%3D+%28subpet+%3D%3D+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
如何将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)
});
这样的