A LINQ question: map query expression to c# code
How do I translate the following query expression to corresponding C# code? Thanks.
var list1 = (from ol in orderedList
开发者_如何学JAVA from er in ol.Er
from rd in er.Rd
where rd.ftr != ""
select ol).ToList<CRInfo>();
It would translate to something like this:
var list1 = orderedList.SelectMany(ol => ol.Er, (ol, er) => new { ol, er })
.SelectMany(z => z.er.Rd, (z, rd) => new { z, rd })
.Where(z2 => z2.rd.frt != "")
.Select(z2 => z2.z.ol)
.ToList<CRInfo>();
The "z" and "z2" bits are transparent identifiers, used by the C# compiler to propagate multiple range variables through the query.
You may want to download LINQPad, which I believe lets you translate query expressions like this very easily.
Well, aside from the obvious fact that your code is already C# code...
I assume you want to obtain the actual Enumerable method calls? If so, you could just compile it and throw it into Reflector.
精彩评论