你能帮我用lambda表达式重写这个查询语法吗?
(From Entity.Apple a in db.Context.Apples
From Entity.Bikini b in db.Context.Bikinis
Where a.Id== 10
Where b.Id== 15
Select new {NaturalColor: a.Color, FavoriteColor: b.Color }).FirstOrDefault();
我尝试查找两个不相关的表的特定记录,一个连接。在我的例子中,下一步可能是:
FindColorDiffrent(Naturalcolor, FavoriteColor){}
答案 0 :(得分:3)
db.Context.Apples
.SelectMany(a => db.Context.Bikinis, (a, b) => new {a, b})
.Where(x => x.a.Id == 10)
.Where(x => x.b.Id == 15)
.Select(x => new {NaturalColor: x.a.Color, FavoriteColor: x.b.Color })
.FirstOrDefault();