views:

23

answers:

1

I have a web server control that is dynamically generated based on a table in my entity framework. Now a decision is being made to have an identically structured table with a different set of data, and I need some way to dynamically repoint my control to the other table. (I have made my case for keeping one table and just adding a flag so lets not go down thatroad please)

I could do this using linq-to-entities, by adding the new table to my entity model, and just conditionally querying one or the other table in the model. The problem is the results returned by the query will be collections of two different entity classes. This poses a problem with all the code that deals with these collections, as it will have to be modified and potentially duplicated to make this work.

So if I can somehow map the results of the linq queries such that regardless of which table I query, the results are of the same class type, then it will minimize the impact on the rest of the code. How would I accomplish something like the below where the two different tables can be materialized as a list of the same class type?

Note that I am using .NET 3.5

var formFooQuery;
if(mode1 == true)
{
        formFooQuery = from r in EntitiesContext.Foo1Set.Include("Foo1Data")
                                where r.FooId == fooId
                                select r;
}
else
{
        formFooQuery = from r in EntitiesContext.Foo2Set.Include("Foo2Data")
                                where r.FooId == fooId
                                select r;
}
List<Foo> foos = formFooQuery.ToList<Foo>();
+1  A: 

You could do this in Entity Framework by utilizing the POCO Support.

Reed Copsey
+1 I think that will be good solution once they are using 4.0, but am using 3.5 right now.
AaronLS
@AaronLS: You could try using this: http://code.msdn.microsoft.com/EFPocoAdapter
Reed Copsey