Using different databases

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
gmitelman
Posts: 2
Joined: Fri 22 Oct 2010 19:24

Using different databases

Post by gmitelman » Fri 22 Oct 2010 19:27

I'm working on a project that uses a different database for each deployment. However, the schema for each database is the same.
I don't want to have to create a diagram/set of classes for each database.
LinqConnect seems to hard-code database name as part of its generated code.
Can I set one up and then be able to either through configuration or runtime, switch to the correct database based on deployment?

Thank you.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Tue 26 Oct 2010 10:33

Could you please specify the DBMS (e.g., SQL Server, Oracle, or SQLite) you are connecting to?

Generally, you can set the necessary database name in the connection string when creating a data context object:
http://www.devart.com/linqconnect/docs/ ... ring).html

gmitelman
Posts: 2
Joined: Fri 22 Oct 2010 19:24

Linq To SQL

Post by gmitelman » Wed 27 Oct 2010 11:20

I'm using MySQL.
The problem is not setting the connection string. The issue is that the code that is automatically generated, has schema name as part of the table, so no matter what the connection string, all access ends up going to the schema used when generating the code, not the one I actually want to use.

For example:
I have 2 databases, db1 and db2 that are both identical in design. If I use db1 when generating the LinqConnect code, then db1 prefix is put into the generated code. So when I point connection string at db2, all my access still happens against db1, not db2.

I want to know how to override it or prevent schema name from being put into the generated code. I confirmed that if I take schema name out of generated code, it works as expected, but I don't want to be in the business of removing schema name every time I re-generate the data access code.

Thank you.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Thu 28 Oct 2010 15:39

The schema name is always stored in order to handle the case of working with objects from several schemas in a single model.

The possible way to change this behaviour is to change the code generation template as it is described in the following topic:
http://www.devart.com/forums/viewtopic.php?t=17930

Please tell us if this helps.

Post Reply