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

社会主义新天地 提交于 2019-12-11 11:08:42

问题


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 with 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'.


回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/4592226/designing-dal-in-net-to-be-data-source-independent-and-not-just-database-ind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!