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
Pattern to easily switch between Oracle and SQL Server (etc)
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
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.
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.