(流畅)NHibernate:映射 IDictionary

发布于 2024-08-19 21:16:58 字数 540 浏览 3 评论 0原文

我找到了很多关于此的帖子,但似乎没有一个能直接帮助我。此外,在 FluentNHibernate 开发的不同阶段,解决方案是否有效似乎也存在混淆。

我有以下课程:

public class MappedClass
{
    ...
}

public enum MyEnum
{
    One,
    Two
}

public class Foo
{
    ...
    public virtual IDictionary<MappedClass, MyEnum> Values { get; set; }
}

我的问题是:

  1. 我需要一个单独的(第三个)MyEnum 表吗?
  2. 如何映射 MyEnum 类型?我应该吗?
  3. Foo 的映射应该是什么样的?

我尝试过映射 HasMany(x => x.Values).AsMap("MappedClass")... 这会导致:NHibernate.MappingException:关联引用未映射的类:MyEnum

I've found a number of posts about this but none seem to help me directly. Also there seems to be confusion about solutions working or not working during different stages of FluentNHibernate's development.

I have the following classes:

public class MappedClass
{
    ...
}

public enum MyEnum
{
    One,
    Two
}

public class Foo
{
    ...
    public virtual IDictionary<MappedClass, MyEnum> Values { get; set; }
}

My questions are:

  1. Will I need a separate (third) table of MyEnum?
  2. How can I map the MyEnum type? Should I?
  3. What should Foo's mapping look like?

I've tried mapping HasMany(x => x.Values).AsMap("MappedClass")...
This results in: NHibernate.MappingException : Association references unmapped class: MyEnum

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

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

发布评论

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

评论(1

萌无敌 2024-08-26 21:16:58

看起来这个问题是 用于映射 IDictionary?的流畅代码的重复。解决方案是使用 hbm.xml 来映射三元关联表。看起来当时 FluentNHibernate 的 AsTernaryAssocation() 方法仅适用于实体类型。我不知道这是否已经改变,或者是否是一个计划中的功能。

It looks like this questions is a duplicate of Fluent code for mapping an IDictionary<SomeEntity, int>?. The solution was to use hbm.xml to map a ternary association table. It looks like at the time FluentNHibernate's AsTernaryAssocation() method only worked for entity types. I can't tell if this has changed, or if it is a planned feature.

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