简体   繁体   English

Nhibernate的真实世界复杂示例

[英]Real world complex example of Nhibernate

The project on which i am working has a very complex business and data logic. 我正在处理的项目具有非常复杂的业务和数据逻辑。 I have around 90 tables and 250 stored procedures in my database. 我的数据库中大约有90个表和250个存储过程。

I have seen very basic samples on Nhibernate through which the operations are performed on database. 我在Nhibernate上看到了非常基本的示例,通过这些示例可以在数据库上执行操作。

I just want to know if we have a huge complex logic then how can we use nhibernate. 我只想知道我们是否有庞大的复杂逻辑,那么我们如何使用nhibernate。

Also currently in some scenarios I handle the business logic at stored procedure level so if there is a slight change just making some changes in stored procedure sets things right for me. 目前在某些情况下,我也会在存储过程级别上处理业务逻辑,因此,如果有轻微更改,只需对存储过程进行一些更改就可以解决问题。 But if i am using Nhibernate how can i work with stored procedures and create complex situations work for me. 但是,如果我使用的是Nhibernate,我该如何使用存储过程并创建复杂的情况为我工作。

Can i get sample code in C# which uses nhibernate and contains complex real world scenarios. 我可以在使用nhibernate并包含复杂现实场景的C#中获得示例代码吗?

An ORM such as NHibernate's primary goal is to abstract database access from the application and render it database agnostic. 诸如NHibernate之类的ORM的主要目标是从应用程序抽象数据库访问并使其与数据库无关。 Having business logic inside stored procedure means that using an ORM will not bring any value whatsoever. 在存储过程中拥有业务逻辑意味着使用ORM不会带来任何价值。 Using plain ADO.NET would be more straightforward and beneficial. 使用普通的ADO.NET将更加直接和有益。 IMHO using NHibernate to call plain SQL or stored procedures is useless. IMHO使用NHibernate调用普通SQL或存储过程是没有用的。 You are just putting an additional layer to your application that wouldn't bring any value. 您只是在应用程序中增加了一层,不会带来任何价值。

However if you move the business logic away from the database and have a nice object model an ORM could be really helpful to map this model to database tables. 但是,如果您将业务逻辑从数据库中移开,并且拥有一个不错的对象模型,那么ORM确实可以帮助将该模型映射到数据库表。

Not only can stored procedures be called through NHibernate, but the ORM enables you to call these procedures in such a way that their result sets are converted automatically to specific entity types. 不仅可以通过NHibernate调用存储过程,还可以使用ORM调用这些过程,从而将其结果集自动转换为特定的实体类型。

See http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!241.entry for an example. 有关示例,请参见http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!241.entry Specifically, you need to use the <sql-query> element of NHibernate's mapping files to set up the name, input parameters, and return type for your stored procedure. 具体来说,您需要使用NHibernate映射文件的<sql-query>元素来设置存储过程的名称,输入参数和返回类型。 You can then refer to this stored procedure in code by the name you've provided. 然后,您可以使用提供的名称在代码中引用此存储过程。

I don't believe you can call stored procedures nakedly. 我不相信您可以裸露地调用存储过程。 They have to be given a name somewhere within the NHibernate mapping files. 必须在NHibernate映射文件中的某个位置为它们指定名称。

As for complexity, I am completely on board with the challenges you're facing. 至于复杂性,我完全接受您所面临的挑战。 I'm giving NHibernate a test run in my own projects to measure its performance and how much it boxes you in when you need flexibility. 我正在我自己的项目中对NHibernate进行测试,以评估其性能以及在需要灵活性时可以放入多少盒。 So far, I haven't had any issues. 到目前为止,我还没有任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM