在运行时添加nHibernate映射? [英] adding an nHibernate mapping at run time?

查看:80
本文介绍了在运行时添加nHibernate映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

尝试使用nHibernate时出现映射失败.该应用程序由几个程序集组成.程序集之一是有用的例程库,另一个是使用该库的应用程序代码.库程序集将自身添加到nHibernate配置中,但是由于它不了解其他程序集,因此不会添加它们.我的xml映射文件位于应用程序程序集中.我认为找不到它是因为它不在应用程序组装中.

I'm getting a mapping failure when trying to use nHibernate. The application consists of several assemblies. One of the assemblies is a library of useful routines and the other is application code that uses the library. The library assembly adds itself to the nHibernate configuration but since it doesn't know about other assemblies it doesn't add them. My xml mapping file is located in the application assembly. I think it's not finding it because it's not looking in the application assembly.

问题: 您可以在不将其添加到配置的情况下映射到任意程序集中的类吗?

Question: Can you map to a class in an arbitrary assembly without adding it to the configuration?

如果没有,您可以在运行时添加映射吗?

If not, can you add a mapping at run time?

谢谢

p.s. 我确实确保将映射文件标记为嵌入式资源

p.s. I did make sure the mapping file was marked as an embedded resource

更新-09年4月3日

我更改了基础库,以允许在初始化时添加程序集.看来效果很好.

I changed the underlying library to allow adding assemblies at initialization. That seems to work just great.

推荐答案

您可以在构建会话工厂时在运行时添加映射:

You can add mappings at runtime at the moment your session factory is being constructed:

ISessionFactory sf = new Configuration()
    .AddFile("Item.hbm.xml")
    .AddFile("Bid.hbm.xml")
    .BuildSessionFactory();

或带有程序集:

ISessionFactory sf = new Configuration()
    .AddAssembly("NHibernate.Auction")
    .BuildSessionFactory();

这篇关于在运行时添加nHibernate映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆