user153923
user153923

Reputation:

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 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.

Upvotes: 0

Views: 217

Answers (3)

user153923
user153923

Reputation:

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:

and

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

Upvotes: 0

Akash Kava
Akash Kava

Reputation: 39956

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");

Upvotes: 2

Related Questions