0

I have two (2) SqlServerCe SP2 databases in my DataAccess project.

For the purposes of this explanation, let's say one database is Company.sdf and the other is Private.sdf. Both databases have the exact same structure: Same tables, same column IDs, etc.

The Company.sdf database contains the latest information on all products, as downloaded from our company's server to allow Engineers and Sales Personnel to access information when network connections are not available.

The Private.sdf database contains any projects or scenarios that Engineers and Sales Personnel have created to build a system or estimate a cost.

I started by creating an Entity Model for the Company.sdf database called CompanyModel. I finally got the Entity Model to connect to it after some difficulty (Entity Framework Noobie).

Today, I created my second Entity Model for the Private.sdf database called PrivateModel. As soon as I did this, I got multiple errors stating that each member of my DataAccess project already contains a definition for a similar item in the other database.

R A T S !

How do I add Entity Models for similar databases?

The DataAccess project is going to be my DAL in my n-tier approach. While searching here for answers, I read RPM1984's response in 3013146 about how a model should know nothing about which database its connecting to - this is the job of your DAL Repository, but I'm not sure how to best do this for my situation.

4

3 回答 3

2

如果你有相同的结构,那么你不需要创建两个模型。您只能使用不同的连接字符串创建一个模型并使用不同的实例连接到不同的数据库。

您的上下文可以将连接字符串作为构造函数中的参数,并且您可以在其中指定两个不同的连接字符串。

只需创建一个模型 MyModel,

MyModelEntities companyContext = 
    new MyModelEntities("company connection string");

MyModelEntities privateContext = 
    new MyModelEntities("private connection string");
于 2011-05-25T17:25:23.973 回答
0

我正在寻找的实际答案似乎只能通过调用EdmGen2来解决。我会进一步更新大家。

如果有人知道实际执行此操作的方法,请随时发表评论或添加答案。

与此同时,我陷入了教程模式。

更新:

SteveQ56 在 CodeProject 上向我指出了一些很好的参考资料:

这些似乎为我指明了我想要去的方向,而不必依赖 EdmGen2。

于 2011-05-25T20:33:28.210 回答