如何在 LINQ 实体框架 4 中编写此 SQL
select C.CenterID
from dbo.Center C
inner join (select PersonID, max(EffectiveDate) as EffectiveDate
from Center
where EffectiveDate <= getdate()
group by PersonID) as C2
on C.PersonID= C2.PersonID
and C.EffectiveDate = C2.EffectiveDate
中心表有一个PersonID和EffectiveDate,多个记录有相同的PersonID,但不同的EffectiveDates,理想情况下我试图为每个PersonID返回1条最新记录
,我想在linq中将其表达为IQueryable,以便我可以使用它构建更大的查询。
select C.CenterID
from dbo.Center C
inner join (select PersonID, max(EffectiveDate) as EffectiveDate
from Center
where EffectiveDate <= getdate()
group by PersonID) as C2
on C.PersonID= C2.PersonID
and C.EffectiveDate = C2.EffectiveDate
Center table has an PersonID and EffectiveDate, multiple records have the same PersonID, but different EffectiveDates, I'm trying to return the 1 most current record for each PersonID
ideally, I want to express this in linq as IQueryable so that I can use it to build larger queries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)