Answer the question
In order to leave comments, you need to log in
C# multi-database project?
I'm getting acquainted with C# and faced the following task, which I don't know how to solve.
There are many different Objects, each with a finite set of fields that are known in advance. It is necessary to organize support for storing each such Object in different databases (oracle, mysql, firebird, interbase and postgres). In them, it can be stored in different ways, up to the fact that its different parts will be in different tables, the names of the fields and tables will be different.
(storage support - in the sense that the software should be able to read records from the selected database, change, delete them)
Maybe I ask a little chaotically, along the way, if necessary, I will clarify. But, can anyone advise the Right Way, Best Practice, suggest how it can be implemented correctly and beautifully?
Answer the question
In order to leave comments, you need to log in
For the Entity Framework, this situation is standard, except that the visual editor does not support it. We create one conceptual model, create a storage model for each database, and for each database create our own mapping of the storage model to the conceptual one.
If to use ORM the answer is obvious. You will use the tools built into them, as well as struggle with their limitations.
In principle, the answer is this: highlight the classic DAL - Data Access Layer. There are many standard patterns for this. For example:
interface ICarData
{
void Insert(Car car);
Car GetById(int id);
// и т.д.
}
Usually use Object to Relation Mapping (ORM) Frameworks. We use NHibernate (to work with MSSQL, SQLite and Mysql). It is configured using adapters, and if you do not use direct queries to the database, then LINQ over NHibernate works quite well with these databases transparently for the programmer. There are adapters for Interbase and other databases too.
In the case of “different parts in different tables”, a data access layer is needed, for example, for each storage case. This layer will return a set of required data according to the specified criteria, isolating access specifics from the programmer and making access to the database more transparent.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question