开发者

NHibernate in a class library?

开发者 https://www.devze.com 2023-02-11 15:46 出处:网络
I have a Visual Studio 2010 MVC 3 web solution containing a number of projects. One of these projects is my site, another handles data access.

I have a Visual Studio 2010 MVC 3 web solution containing a number of projects. One of these projects is my site, another handles data access.

I am using NHibernate to access my database and I have put all my mapping files, nhibernate.config and NH DLLs inside the data access project.

I have enough of an idea how to use NHibernate but I've only ever used it in small, single test projects - never a solution with multiple projects

I want to reference the nhibernate.config in开发者_开发百科 my site's web.config - can I do that? If not what should I do? Put all the the NH DLLs in my site's bin folder and stick the NH config straight into my DLL?

Totally lost - all help appreciated!


I would put nhibernate.config in your web project and your data access layer would create a session factory like this:

private ISessionFactory CreateSessionFactory()
{
    Configuration cfg;
    cfg = new Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "nhibernate.config"));
    return (cfg.BuildSessionFactory());
}

Always searching nhibernate.config in a base directory, so you can reference your DAL in other projects.

0

精彩评论

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