如何将多个MIN函数编码为一个LINQ to DataSet查询

时间:2011-05-03 16:45:10

标签: c# linq oracle linq-to-dataset

好的,在寻求帮助之前,我一直在研究这个问题。我有4个基于Oracle的SQL查询,它们相互跟随以传递请求的数据。我在.NET工作,我想(我希望)我可以使用LINQ to DataSet将第一个查询传递给第二个查询,传递给第三个查询,最后传递给第四个查询。在我头疼的地方,从第一个到第二个。我可以通过普通的ODP.NET和C#查询获得第一个查询到DataSet。

这是第2步

SELECT eid,
num_1,
MIN(cdts) keep (dense_rank FIRST ORDER BY eid) first_creation,
cpers,
curent,
ag_id,
beat,
group_priority,
disp_date,
MIN(disp_time) keep (dense_rank FIRST ORDER BY eid) first_call,
curent_16,
MIN(ad_sec) keep (dense_rank FIRST ORDER BY eid) first_entry,
MIN(ds_sec) keep (dense_rank FIRST ORDER BY eid) first_dispatched,
MIN(ar_sec) keep (dense_rank FIRST ORDER BY eid) first_arrival,
MIN(csec) keep (dense_rank FIRST ORDER BY unid) fastest_unit,
MIN(hold_sec) keep (dense_rank FIRST ORDER BY eid) fastest_dispatch,
MIN(drive_sec) keep (dense_rank FIRST ORDER BY unid) fastest_enroute,
MIN(resp_sec) keep (dense_rank FIRST ORDER BY unid) fastest_arrival,
unid FROM JC5A_STEP1 GROUP BY eid,
num_1,
cpers,
curent,
ag_id,
beat,
group_priority,
disp_date,
curent_16,
unid HAVING cpers <> 0 AND curent = 'T' AND curent_16 ='T' ORDER BY eid;

我一直在尝试编写一个LINQ to DataSet,它将把它填充到自己的DataSet中。 这就是我到目前为止,我知道我已经离开了

var query2 = (from row in query1.AsEnumerable() where row.Field<int32>("cpers") != 0 && row.Field<string>("curent") == "T" && row.Field<string>("curent_16") == "T" order by row.Field<Int32>("eid") select new { eid = row.Field<Int32>("eid"), ... }).Min(x => x.cdts); 

我省略了所有非最小字段和为简洁而包含的字段。所以,我的问题是,我可以编写一个LINQ to DataSet查询,它将包含我在SELECT语句中的内容,如果是这样,我在哪里可以解决问题?如果没有,我是否需要在PL / SQL函数中开发所有这些并从应用程序中调用它们作为存储过程?

感谢大家的帮助,

吨。

根据快速反馈,第一个查询在此处:

select a.eid, a.num_1, e.cdts, e.cpers, a.curent, a.tycod, a.ag_id, a.lev3 as beat, case when a.priority < '2' then 'high' when a.priority > '2' then 'low' else 'normal' end as group_priority, substr(e.cdts,5,2)||'/'||substr(e.cdts,7,2)||'/'||substr(e.cdts,1,4) as disp_date, substr(e.cdts,9,6) as disp_time, e.curent AS curent_16, a.ad_sec, a.ds_sec, a.ar_sec, u.csec, a.ds_sec - a.ad_sec as hold_sec, u.csec - a.ds_sec as drive_sec, u.csec - a.ad_sec as resp_sec, a.priority, u.unid from un_hi u join (aeven a join event e on a.eid = e.eid) on u.eid = a.eid where e.cdts between '20110101' and '20110201' and a.tycod not in ('ANIMAL', 'BUSINESS', 'CARCHECK', 'CARSTAT', 'CIVSERV', 'CKLIGHTS', 'COURT', 'ERRAND', 'FOLLOW', 'FOOTPURS', 'GREATMAL', 'HOUSE', 'INFO', 'K9', 'PEDCHECK', 'PRISONER', 'RESIDENC', 'SELF', 'SPECIAL', 'STATION', 'TELEPHON', 'TRAFFIC', 'TRASH', 'WARRANT', 'WEATHER') and u.unit_status = 'AR' and a.ag_id = 'JCSO' and a.lev3 = 'JC5' and a.ar_sec is not null and a.ds_sec is not null and a.ds_sec - a.ad_sec between 1 and 7200 and a.ar_sec - a.ds_sec between 1 and 18000 and a.ar_sec - a.ad_sec between 1 and 18000 and u.csec - a.ds_sec > 1 and u.csec - a.ad_sec > 2 order by e.cpers, a.eid, u.csec;

1 个答案:

答案 0 :(得分:0)

我会考虑使用linq来为你的问题而不是linq到数据集。您可以直接使用c#来编写查询,而不是在sql中编写查询,这可以为您提供更多选项(自定义对象),而无需处理DataSet和朋友的限制和头痛。