LINQ:点符号相当于JOIN [英] LINQ: dot notation equivalent for JOIN

查看:165
本文介绍了LINQ:点符号相当于JOIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑使用查询符号这样写LINQ表达式:

Consider this LINQ expression written using query notation:

 List<Person> pr = (from p in db.Persons
                     join e in db.PersonExceptions
                     on p.ID equals e.PersonID
                     where e.CreatedOn >= fromDate
                     orderby e.CreatedOn descending
                     select p)
                   .ToList();



问:你会怎么写使用点符号这个LINQ表达式

Question: how would you write this LINQ expression using dot notation?

推荐答案

这样的:

List<Person> pr = db.Persons
                    .Join(db.PersonExceptions,
                          p => p.ID,
                          e => e.PersonID,
                          (p, e) => new { p, e })
                    .Where(z => z.e.CreatedOn >= fromDate)
                    .OrderByDescending(z => z.e.CreatedOn)
                    .Select(z => z.p)
                    .ToList();

请注意新的匿名类型是如何引入到同时携带 P 电子位前进。在规格上,查询操作而做到这一点使用的透明的标识符的指示的行为。

Note how a new anonymous type is introduced to carry both the p and e bits forward. In the specification, query operators which do this use transparent identifiers to indicate the behaviour.

这篇关于LINQ:点符号相当于JOIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆