我对所有这些技术都是新手。我想看一个简单的(不是过度的)示例,说明如何使用这些技术建立一个项目。最重要的是正确的 NHibernate 会话处理(使用 HttpContext)。或者我们可以在我已有的基础上进行构建。
我见过一些这样或那样的例子,但没有看到所有这些技术混合在一起的例子。我很难将它们联系在一起。
现在我有一个 NHibernateHelper 类
(<-- 请参阅pastebin 链接)有人给我提供了一个例子。我稍微修改了一下。我想我需要在我的 Global.asax.cs 文件中做一些事情,但我不确定具体是什么。我需要以某种方式通过向 NHibernateHelper 的构造函数传递一个 Assembly 来初始化它......但是什么样的 Assembly 呢?这就是我真正迷失的地方。我缺少什么?
I'm new to all of these technologies. I would like to see a simple (not over the top) example of how you would set up a project with these technologies. The most important being the proper NHibernate session handling (using HttpContext
). Or we can build off of what I already have.
I've seen several examples of one piece or another but nothing with all of these technologies mixed. I'm having a tough time tying them together.
Right now I have an NHibernateHelper class
(<-- see the pastebin link) that someone provided me as an example. I've modified it slightly. I think I need to do some stuff in my Global.asax.cs
file but I'm not sure exactly what. I need to somehow initialize the NHibernateHelper
by passing its constructor an Assembly... but what kind of Assembly? This is where I get really lost. What am I missing?
发布评论
评论(1)
在您的示例中,Assembly 参数是包含所有映射文件 (hbm.xml) 或映射类(Fluent nhibernate)的程序集。
我想推荐您阅读此教程。这就是我通常所做的,创建一个新的 HttpModule,每个请求打开一个新会话并将其绑定到 Web 上下文。请求结束时,会话关闭。 这是同一实现的另一个示例,
虽然帖子是用 pt-BR 写的,但代码是英文的。
In your example, The Assembly parameter is the Assembly that contains all Mapping files (hbm.xml) or Mapping classes (fluent nhibernate).
I'do like to recommend you to read this Tutorial. This is how i usually do, create a new HttpModule that opens a new session once per request and binds it to the web context. At the end of the request the session is closed. This is another example of the same implementation,
although the post is written in pt-BR, the code is in english.