NHibernate 中的多个 ClassMap 类

发布于 2024-09-19 13:55:42 字数 171 浏览 2 评论 0原文

在一个表具有多个映射的流畅的 nhibernate 中这可能吗?假设我有一个用户表。

一旦我希望它像在文件 UserMap1.cs 中一样应用,有时我更喜欢从 UserMap2.cs 进行映射。

我不需要在应用程序运行时切换配置。我只需要在一开始就选择一个合适的。

提前致谢:-)

Is this possible in fluent nhibernate having multiple mappings for one table? Lets suppose i have a Users table.

Once i want it to be apped exactly like in file UserMap1.cs, and some times I would rather prefer mapping from UserMap2.cs.

I don't need to switch configurations while app is running. I just have to choose a proper one at the beginning.

Thanks in advance:-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耳钉梦 2024-09-26 13:56:56

您正在使用 Fluent NHibernate,因此您可能会使用 Mappings.FluentMappings 对象。我通常调用 AddAssemblyFrom (在包含映射的程序集中提供类型)。您可能需要调用 Add 或 Add(Type type) 方法来单独添加它们。我的想法是使用 MEF 来归属 ClassMap 子类,并在选定的情况下添加元数据以确定要注入哪些子类。

You're using Fluent NHibernate, so you're likely using the Mappings.FluentMappings object. I normally invoke AddAssemblyFrom (providing a type in the assembly containing mappings). You may need to invoke the Add or Add(Type type) method to add them invididually. My thought is to use MEF to attribute your ClassMap subclasses and add metadata in select cases to determine which ones to inject.

酒中人 2024-09-26 13:56:40

这可能是一种黑客行为,但您可以将两个映射放入不同的命名空间中。然后,您可以根据需要从一个名称空间或另一个名称空间添加映射。

This might be a hack, but you could possibly put your two mappings into separate namespaces. Then you could add mappings from either one namespace or the other depending on your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文