开发者

Designing DAL in .NET to be "data-source independent" and not just "database independent"?

开发者 https://www.devze.com 2023-02-02 22:56 出处:网络
How to design such flexible DAL (specifically in .NET) ? What interfaces .NET provides and what should be done on my own ?

How to design such flexible DAL (specifically in .NET) ?

What interfaces .NET provides and what should be done on my own ?

Its a greenfield project starting with SQL Server as data source but in future, parts of it will move to different NoSQL type of datastores.

Also, we may need to experiment wit开发者_StackOverflowh lot of different datastores (like some data may have to go with Cassandra, some with RDBMS, some to other DHT etc.)

Therefore easily switchable access layer will be needed. All i know right now is the 'data' and 'operations needed on that data'.


Simply: you do not. Ths is not so much about technology, but about totally different behavioral characteristics between different stores.

For example, SQL really shines in queries, and any decent DAL will expose those in a dynamic fashion (i..e no "GetCustomerById" function).

Replacing this with a XML File will be horrific and put a lot of stress on the DAL side - you need to reimplement a very powerfull search semantics without the proper disc structures to speed it up.

Most NoSQL data stores seriously ysuck once you get used to the proper relational theorem. They are not compareable in behavior and functionality, and as such a DAL can not abstract this away in a nontrivial project.


Ok, it's a bit of a fluffy question, but you might get some ideas if you look at something like NHibernate. I'm not suggesting you adopt it (or don't adopt it) but you'll see how a mature framework like that separates repository specifics from the code.

Also, take a look at how the framework defines connections, commands, etc for SQL Server. There's a SqlConnection which implements IDbConnection. If your code then operates on IDbConnection you are free to switch to say an oracle connection (well in theory).

0

精彩评论

暂无评论...
验证码 换一张
取 消