Ok, I've been working on this one for a while before asking for assistance. I have 4 Oracle based SQL queries which follow one another to deliver the requested data. I'm working in .NET and I think (I hope) I could use LINQ to DataSet to pass the first query along to the second, which passes to the third, and finally to the fourth. Where I'm running into a headache is with passing from the first to the second. I can get the first query into a DataSet through normal ODP.NET and C# queries.
Here is step 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;
I've been trying to write a LINQ to DataSet which will populate this into a DataSet of its own. This is what I have so far and I know I'm way off
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);
I omitted all of the non-min fields and the one which is included for brevity. So, my question is, can I write a LINQ to DataSet query which will encompass what I have in the SELECT statement, and if so, where am I off my rails? If not, will I need to develop all of this in PL/SQL functions and call them from the application as Stored Procedures?
Thanks to everyone for any assistance,
T.
Based on a quick feedback, the first query is here:
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;
I would look into using linq to sql for your problem instead of linq to datasets. Instead of writing your query in sql you can do it using c# directly which could afford you more options (custom objects) without the limitation and headache of dealing with the DataSet and friends.