What is the return type of my linq query?

Posted by Ulhas Tuscano on Stack Overflow See other posts from Stack Overflow or by Ulhas Tuscano
Published on 2011-02-16T07:06:34Z Indexed on 2011/02/16 7:25 UTC
Read the original article Hit count: 165

Filed under:
|

I have two tables A & B. I can fire Linq queries & get required data for individual tables. As i know what each of the tables will return as shown in example. But, when i join both the tables i m not aware of the return type of the Linq query. This problem can be solved by creating a class which will hold ID,Name and Address properties inside it. but,everytime before writing a join query depending on the return type i will have to create a class which is not a convinient way Is there any other mathod available to achieve this

  private IList<A> GetA()
    {
        var query = from a in objA
                    select a;
        return query.ToList();
    }

    private IList<B> GetB()
    {
        var query = from b in objB
                    select b;
        return query.ToList();
    }

    private IList<**returnType**?> GetJoinAAndB()
    {
        var query = from a in objA
                    join b in objB
                    on a.ID equals b.AID
                    select new { a.ID, a.Name, b.Address };
        return query.ToList();
    }

© Stack Overflow or respective owner

Related posts about .NET

Related posts about LINQ