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();
}
The value you generate is called Anonymous Type and you can return it unless you return
objectlike:There are two good solutions:
1. is to generate a class to match the output and generate it like Kobi solution
2. if you are using .net 4 you can return a
dynamictype likethen you can use it later. You can search the internet about the advantage of using
dynamickeyword.