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!

2 Answers 2

2
aList.SelectMany(a => a.bList)
     .SelectMany(b => b.cList)
     .Where(c => c.cfoo == "\"Test\"");
Sign up to request clarification or add additional context in comments.

1 Comment

To get this to work with dynamic linq I needed to modify this as follows: aList.SelectMany(a => a.bList) .SelectMany(b => b.cList).AsQueryable().Where("foo = \"Test\""); `
0

Try this:

aList.SelectMany(a => a.bList.SelectMany(b => b.cList))
    .Where(c => c.cf002 == "Test")
    .Select();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.