Multiple connection with Open access entity model

494 Views Asked by At

I wonder if I can have multiple connection on entity model such as -

using (var db = new VWEntitiesModel("data source=Dev;initial catalog=Website1;user id=sqluser;password=&&password"))
{
    some logic
}

using (var db = new VWEntitiesModel("data source=Dev;initial catalog=Website2;user id=sqluser;password=&&password"))
{
    some logic
}

I'm using Telerik Openaccess Entity model. I tried to use as above. It seems like it doesn't like it. Any advice please ?

1

There are 1 best solutions below

0
On

An EntityModel (OpenAccessContext derived type) represents the conceptual model that is mapped to tables in the database. The difference in the connection strings that you have specified above is the 'Initial Catalog'. To work with the same model against two different databases would require them to be exactly the same as far as the objects (tables,column,constraints etc) known to the domain model are concerned.

You can specify two unique connection strings but this would result in OpenAccess maintaining a unique workspace (metadata,caches,connection pool etc) for each unique connection string that you use.

If your service is querying two different databases you should have two independent domain models that represent the databases and instantiate them with the appropriate connection string.