Page 1 of 1

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

Posted: Wed 08 Feb 2012 17:03
by kclubb
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

Posted: Thu 09 Feb 2012 16:18
by StanislavK
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.