.net - Converting two loops to single LINQ query using C# -
i searched links here change nested loops single linq, tried using those, part of code not working, need expert guidance fix this,
update 1:
i guess wasn't clear in explanation, loops works fine! expected, getting correct results, doing optimization, instead of using 2 loops need same code converted single linq.
here code :
foreach (var ob in all_request_list.where(x => x.startdate != x.enddate)) { int consq_dates = ob.enddate.datediff(ob.startdate); (int = 0; <= consq_dates; i++) { combined_list.add(new { shiftid = ob.shiftid, skillid = ob.skillid, employeeid = ob.employeeid, assigndate = ob.startdate.adddays(i), profileid = ob.profileid }); } }
i have problem adding increment variable i
ob.startdate.adddays(i)
.
any appreciated.
is you're looking for?
var items = ob in all_request_list ob.startdate != ob.enddate let consq_dates = ob.enddate.datediff(ob.startdate) in enumerable.range(0, consq_dates + 1) select new { shiftid = ob.shiftid, skillid = ob.skillid, employeeid = ob.employeeid, assigndate = ob.startdate.adddays(i), profileid = ob.profileid }; combined_list.addrange(items);
but: you've code works. understand code. why wan't change that? btw: 2 loops faster linq.
Comments
Post a Comment