0

If I have class structure as follows:

    private class A
    {
        int afoo { get; set; }
        B[] bList { get; set; }
    }

    private class B
    {
        String bfoo { get; set; }
        C[] cList { get; set; }
    }

    private class C
    {
        String cfoo { get; set; }
        int cfoo2 { get; set; }
    }

    public class Master
    {
        A[] aList;

        //qry for all where A.B.C.cfoo = "test"
    }

How would I construct a dynamic LINQ statement to query for items in class C? Something like this

1) var qry = aList.blist.clist.AsQueryable().Where("cfoo = \"Test\"").Select();

My ultimate solution would be to pass the entire path in the dynamic part like this:

2) var qry = aList.AsQueryable().Where("bList.cList.cFoo = ""Test"").Select();

But from what I have tried you can not have the nested objects in the Where. So I am going to live with using templates to build the methods as in 1) above.

[Also, I am using the dynamic library from Scott Gu for the dynamic part.]

But, I can't get that to work. Any suggestions?

Thanks!

4

2 回答 2

2
aList.SelectMany(a => a.bList)
     .SelectMany(b => b.cList)
     .Where(c => c.cfoo == "\"Test\"");
于 2012-07-13T18:54:16.740 回答
0

尝试这个:

aList.SelectMany(a => a.bList.SelectMany(b => b.cList))
    .Where(c => c.cf002 == "Test")
    .Select();
于 2012-07-13T18:53:25.853 回答