[英]linq with max date in sub query
I need to select a record that joins to another table with status and an insert DateTime. 我需要选择一个连接到具有status和插入DateTime的另一个表的记录。 I want the record that corresponds to the AgreementStatuses with the maximum Date_Created
我希望与AgreementStatuses对应的记录具有最大Date_Created
from c in Agreements
join a in AgreementStatuses on c.Agreements_ID equals a.Agreements_ID
join s in Statuses on a.Statuses_ID equals s.Statuses_ID
where DateTime.Now > c.BeginDate
&& DateTime.Now < c.TermDate
&& c.ControlPlan_ID == 31
&& s.StatusText == "Promoted"
&& c.AlphaPrefix == "PEH"
&& c.States_ID == 33
&& a.Date_Created == (from n in AgreementStatuses //ERROR HERE
join y in Statuses on n.Statuses_ID equals y.Statuses_ID
where y.StatusText == "Promoted"
&& n.Agreements_ID == 584
group n by n.Agreements_ID into g
select new {Date_Created = g.Max(t=>t.Date_Created)}).FirstOrDefault()
select c
error: 错误:
Operator '==' cannot be applied to operands of type 'DateTime' and '<anonymous type: DateTime Date_Created>'
Thanks jdweng. 谢谢jdweng。 That did it.
这样做了。
from c in Agreements
join a in AgreementStatuses on c.Agreements_ID equals a.Agreements_ID
join s in Statuses on a.Statuses_ID equals s.Statuses_ID
where DateTime.Now > c.BeginDate
&& DateTime.Now < c.TermDate
&& c.ControlPlan_ID == 31
&& s.StatusText == "Promoted"
&& c.AlphaPrefix == "PEH"
//&& c.States_ID == 33
&& a.Date_Created == (from n in AgreementStatuses
join y in Statuses on n.Statuses_ID equals y.Statuses_ID
where y.StatusText == "Promoted"
&& n.Agreements_ID == a.Agreements_ID
group n by n.Agreements_ID into g
select g.Max(t=>t.Date_Created)).FirstOrDefault()
select c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.