Reputation: 379
I know we can add an external XML map file to dynamically alter the table names in a data context. But according to what i have seen on most of the posts, that can be done only if the table structures are same (same columns and primary key).
What i want to know is that, is there a way to dynamically add a new table to the data context when its different from the tables currently in the context.
Or is it possible to achieve this from entity framework?
Upvotes: 0
Views: 945
Reputation: 39946
Another way would be to use EF 4.1 code first where you can generate and compile code dynamically and load them in your app domain. Well I think you can use dynamic compilation for EF 4.0 as well but Edmx and mappings are complicated.
And it will be new context, you won't be able to change existing context but you may merge in new class library. But this all will have to happen on reflection because you will not have generic types available at compile time for linq.
Upvotes: 0
Reputation: 61037
I'm gonna go a head and say no because the ORM doesn't provide a dynamic run-time model it's a prebuilt static model of the data set that you query against.
Then, all you really need to do to make it dynamic is to rebuilt it as you need it. That will require you to invoke a build when you add new tables or columns but that's not out of the question. And this can be done in a verity of ways.
However, if this is your problem you shouldn't be trying to solve this with an ORM like linq-to-sql. It's was never built for that. I would also recommend entity framework as it has superceeded linq-to-sql in every way (and linq-to-sql is no longer being developed).
Upvotes: 1