views:

18

answers:

1

I am using ASP.NET MVC framework and accessing DB records with Entities. I am doing some joins like this:

public IQueryable<...> GetThem()
{
    var ords = from o in db.Orders 
              join c in db.Categories on o.CategoryID equals c.ID 
              select new {Order=o, Category=c};

    return ords;
}

I need to use/pass 'ords' from one function to other in a strongly-typed manner. (I will be doing this kind of joins in multiple places.)

What is the best way to do this? Do I need create a new class containing both returned vals for every join I do? Eg: public class OrderAndCategory { public Order; public Category; } in this case.

Is there any simpler way?

Thanks!

A: 

The class representing the data in ords is strongly typed, it is generated by the compiler. You could run into problems though if the compiler generates different classes for different instances of the query, but with the same types. You'd have to check that. If this is the case, you'll have to create classes for each different query, or use the class Tuple<Targs...> instead.

Femaref