Pattern to easily switch between Oracle and SQL Server (etc)

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
kclubb
Posts: 1
Joined: Wed 08 Feb 2012 16:54

Pattern to easily switch between Oracle and SQL Server (etc)

Post by kclubb » Wed 08 Feb 2012 17:03

I am evaluating LinqConnect. How would I write my code to ensure that I can easily switch between Oracle and SQL Server (etc). I looks like DB specific code is generated (.CS file).

Ideally I would use Linq in a DB agnostic way, and switch providers in a configuration setting.

Thanks

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

Post by StanislavK » Thu 09 Feb 2012 16:18

The reason why DBMS-specific code is generated is that the attribute mapping mode is used by default. As multiple mapping attributes of the same type cannot be set for a single class/property, the attribute mapping can only be used for a single database.

To make your model database-ignorant, you can use the file mapping mode instead (you can change the mapping mode in the Model Settings dialog). In this case, the mapping metadata will be saved to a [YourModel].xml file. To work with different databases, you can do the following:
- generate several mapping files (e.g., one per DBMS);
- create the mapping source object from a particular mapping file;
- pass this object to your DataContext constructor.

Feel free to contact us if anything is unclear.

Post Reply