NHibernate:如何在运行时重新配置映射?
让我们先解决这个问题:我知道 SessionFactory 是不可变的 - 我试图在运行时更改配置并重新生成 ISessionFactory。
具体来说,我映射了一个客户,它将在运行时将一些字段添加到其动态组件节点。我想做这样的事情
var newSessionFactory = previousConfiguration
.RemoveClassMapping(typeof(Customer))
.AddXmlString(newMappingForCustomer)
.BuildSessionFactory();
但是,我没有看到任何明显的方法来删除映射,除了重新生成整个配置之外,我还能做些什么吗?
Let's get this out of the way first: I know that SessionFactory is immutable - I'm trying to change the Configuration at runtime and regenerate ISessionFactory.
Specifically, I have a Customer mapped that will have some fields added to its dynamic-component node at runtime. I would like to do something like this
var newSessionFactory = previousConfiguration
.RemoveClassMapping(typeof(Customer))
.AddXmlString(newMappingForCustomer)
.BuildSessionFactory();
However, I don't see any obvious way to remove a mapping, is there anything I can do short of regenerating the entire Configuration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是不可能的。您必须重新生成
配置
。我最初的建议是为您的模型选择不同的策略。
但是,如果您决定这样做:-),您可以:
Configuration
(不包括Customer
)MemoryStream
Customer
映射(如果需要)SessionFactory
Customer
所需的任何信息Configuration
Customer
映射并创建最终的It's not possible. You'll have to regenerate the
Configuration
.My initial suggestion would be that you choose a different strategy for your model.
However, if you are determined to go with this :-), you can:
Configuration
(that does not includeCustomer
)MemoryStream
Customer
mapping, if neededSessionFactory
Customer
Configuration
Customer
mapping and create your finalSessionFactory