linq dynamic query

Discussion in 'ASP.NET / ASP.NET Core' started by ramjill, Sep 25, 2012.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. hi,

    i need to convert below static linq expression to dynamic. please check my expression below.

    Collapse | Copy Code
    Class1 objClassBO = datafromdb();

    //This is my linq static expression

    Class2 objClassDC = new Class2()
    {
    Field1 = objClassBO.Field1,
    Field2 = objClassBO.Field2,
    Field3 = objClassBO.Field3.Cast<class3>().Select(j =&gt;new Class4
    {
    Field1 = j.Field1,
    Field2 = j.Field2
    }).ToArray()
    };

    //Sample classes

    public class Class1
    {
    public int Field1 { get; set; }
    public int Field2 { get; set; }
    public Class3[] Field3 { get; set; }
    }

    public class Class2
    {
    public int Field1 { get; set; }
    public int Field2 { get; set; }
    public Class4[] Field3 { get; set; }
    }

    public class Class3
    {
    public int Field1 { get; set; }
    public int Field2 { get; set; }
    }

    public class Class4
    {
    public int Field1 { get; set; }
    public int Field2 { get; set; }
    }

    Thanks in advance
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page