LinqPad:Linq to Sql组查询出错

时间:2012-03-27 19:17:43

标签: linq

我在以下查询中的“group”行收到错误:

int pid;
int eid;

pid = 99926;
eid =   2235;

var query2 = from p in PROVIDERS
    join pae in PROV_APPL_EVENTS on p.PROVIDER_ID equals pae.PROVIDER_ID
    join et in EVENT_TYPES on pae.EVENTTYPE_ID equals et.EVENTTYPE_ID
    **group t by new {p.PROVIDER_ID, pae.EVENTTYPE_ID } into grp**
    where p.PROVIDER_ID == pid && pae.EVENTTYPE_ID == eid
    select new {grp.Key.PROVIDER_ID, 
                grp.Key.EVENTTYPE_ID,
                maxDate = grp.Max(y => y.EVENT_DATE)};

query2.Dump();

错误是

无法将lambda表达式转换为类型'System.Collections.Generic.IEqualityComparer',因为它不是委托类型

我正在使用LinqPad for .Net FW 4.0。

目标是获取EVENT_Date列的最新值。

工作的T-Sql是

SELECT     dbo.PROVIDERS.PROVIDER_ID, dbo.PROV_APPL_EVENTS.EVENTTYPE_ID, dbo.EVENT_TYPES.EVENT_TYPE_NAME, MAX(dbo.PROV_APPL_EVENTS.EVENT_DATE) 
                      AS Event_Date
FROM         dbo.PROVIDERS INNER JOIN
                      dbo.PROV_APPL_EVENTS ON dbo.PROVIDERS.PROVIDER_ID = dbo.PROV_APPL_EVENTS.PROVIDER_ID INNER JOIN
                      dbo.EVENT_TYPES ON dbo.PROV_APPL_EVENTS.EVENTTYPE_ID = dbo.EVENT_TYPES.EVENTTYPE_ID
GROUP BY dbo.PROVIDERS.PROVIDER_ID, dbo.EVENT_TYPES.EVENT_TYPE_NAME, dbo.PROV_APPL_EVENTS.EVENTTYPE_ID
HAVING      (dbo.PROV_APPL_EVENTS.EVENTTYPE_ID = 2235) AND (dbo.PROVIDERS.PROVIDER_ID = 99926)

2012/3/28 我修改了我的linq查询,如下所示:

 Dim pid as Integer
 dim eid as integer

 pid = 99926
 eid = 2235

 dim query2 = from p in PROVIDERS _
join pae in PROV_APPL_EVENTS on p.PROVIDER_ID equals pae.PROVIDER_ID _
join et in EVENT_TYPES on pae.EVENTTYPE_ID equals et.EVENTTYPE_ID _
where p.PROVIDER_ID = pid and et.EVENTTYPE_ID = eid _
group by key = new with {p.PROVIDER_ID, pae.EVENTTYPE_ID, et.EVENT_TYPE_NAME} 
into LatestEventDate = Max(pae.EVENT_DATE) _
select new with {.ProviderId = **p.PROVIDER_ID,** _
.EventTypeId = pae.EVENTTYPE_ID, _
.EventTypeName = et.EVENT_TYPE_NAME, _
LatestEventDate}

query2.Dump()

,错误是: 名称'p'未在当前范围内声明或不声明。

谢谢,

的Piyush

0 个答案:

没有答案