使用 NHibernate 在同一 ASP.NET 应用程序中同时支持 Oracle 和 SQL Server 的建议

2022-01-02 00:00:00 oracle sql-server nhibernate

我们的客户希望在下一个项目中同时支持 SQL Server 和 Oracle.我们的经验来自 .NET/SQL Server 平台.我们将聘请一名 Oracle 开发人员,但我们关注的是 DataAccess 代码.NHibernate 会让数据库引擎对我们透明吗?我不这么认为,但我想听听遇到类似情况的开发人员的意见.

Our client wants to support both SQL Server and Oracle in the next project. Our experience comes from .NET/SQL Server platform. We will hire an Oracle developer, but our concern is with the DataAccess code. Will NHibernate make the DB Engine transparent for us? I don't think so, but i would like to hear from developers who have faced similar situations.

我知道这个问题有点含糊,因为我没有 Oracle 经验,所以我不知道我们会发现什么问题.

I know this question is a little vague, because i don't have Oracle experience, so i don't know what issues we will find.

推荐答案

通过遵循一些基本实践,您可以轻松地使用 NHibernate 使您的应用程序与数据库无关:

You can easily use NHibernate to make your application database-agnostic by following some basic practices:

  • 首先设计您的对象模型.
  • 不要使用任何特定于数据库的代码.您需要具有良好 C# 经验的人,而不是 Oracle 开发人员.不要依赖触发器、存储过程等内容.
  • 让 NHibernate 至少在最初生成 DB 模式(您可以稍后调整索引等内容)它将为每个 DB 选择最佳的可用数据类型.
  • 使用与数据库无关的 POID 生成器(hiloguid)而不是序列或身份.
  • 尽量避免使用 SQL.HQL 和 Linq 在 99% 的情况下都能正常工作.
  • 避免并非所有目标数据库都支持的 NH 功能(例如 Future、MultiCriteria 等)
  • Design your object model first.
  • Do not use any database-specific code. You need somebody with good C# experience, not an Oracle developer. Do not rely on stuff like triggers, stored procedures, etc.
  • Let NHibernate generate the DB schemas at least initially (you can tweak things like indexes later) It will choose the best available datatypes for each DB.
  • Use a DB-agnostic POID generator (hilo or guid) instead of sequences or identity.
  • Try to avoid using SQL. HQL and Linq work fine in 99% of the cases.
  • Avoid NH features that are not supported by all of your target DB (for example, Future, MultiCriteria, etc)

NHibernate 有一个很棒的社区.您可以随时在 http://groups.google.com/group/nhusers 中提问除了在这里发帖.

NHibernate has a great community. You can always ask your questions in http://groups.google.com/group/nhusers besides posting here.

相关文章