开发者

How to use Entity Framework against multiple databases?

开发者 https://www.devze.com 2023-01-07 05:50 出处:网络
I would like to use EF 4.0 against Oracle.The challenge I have is that I have multiple databases (all with nearly identical schemas) for different clients.Is it possible to generate my CRUD layer once

I would like to use EF 4.0 against Oracle. The challenge I have is that I have multiple databases (all with nearly identical schemas) for different clients. Is it possible to generate my CRUD layer once, and then point at the correct database at runtime based on user identity (or whatever criteria I n开发者_如何学JAVAeed to supply)? I think I can handle the small differences between schemas by using POCO classes or just handling it in the partial classes, but I'm not sure how to handle directing to the correct database. Any Ideas?


The most simple solution is to create several named connection strings in your configuration file and then simply to create different instances of the same ObjectContext with different conection string parameter using a parameterized constructor.
Don't forget to delete the Schema attribute from your .edmx file (using XML Editor, for example).

0

精彩评论

暂无评论...
验证码 换一张
取 消