开发者

Similar Databases - Entity Model Framework

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 h开发者_如何学Goave 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.


If you have same structure then you don't need to create two models. You can only create one model and use different instances to connect to different database using just different connection strings.

Your context can take connection string as parameter in constructor and there you can specify two different connection strings.

Just create one model, MyModel,

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

MyModelEntities privateContext = 
    new MyModelEntities("private connection string");


You need to implement the Repository pattern. Here are a few links to a very simple examples.

http://blogs.microsoft.co.il/blogs/gilf/archive/2010/01/20/using-repository-pattern-with-entity-framework.aspx

http://blogs.msdn.com/b/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx


The actual answer I'm looking for appears to be solved only by calling EdmGen2. I will update everyone further.

Feel free to comment or add answers if anyone knows of a way to actually do this.

In the mean time, I'm stuck in tutorial mode.

UPDATE:

I've been pointed to a couple of good references by SteveQ56 on CodeProject:

  • How to: Manually Configure an Entity Framework Project

and

  • How to: Manually Define an Entity Data Model (Entity Framework)

These seem to point me in the direction I want to go without having to fall back on EdmGen2.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜