NHibernate 3.2 通过代码映射 IDictionary

发布于 2024-12-03 15:59:17 字数 1488 浏览 3 评论 0原文

我在使用新的 Loquacious 配置映射到 IDictionary 时遇到问题。

这是类:

public class Person
{
    public Person()
    {
        Description = new Dictionary<int, string>();
    }

    public virtual int Id { get; set; }

    // can be in various languages
    public virtual IDictionary<int, string> Resources { get; set; }
}

public class PersonResource
{
    public virtual string Description { get; set; }
}

这是映射:

public class TestPersonMap : ClassMapping<TestPerson>
{
    Table("TestPersons");

    Id(c => c.Id, m => m.Generator(Generators.HighLow, gm => gm.Params(new { max_low = 1000 })));

    Map(c => c.Resources, mpm =>
                                {
                        mpm.Table("TestPersonResources");
                        mpm.Key(km => km.Column("Id"));
                     },
            mkr => mkr.Component(cem => cem.Property(p => p.Description)));

这会在数据库中生成一个如下所示的表:

TestPersons
-----------
Id

TestPersonResources
-------------------
Id
Description
idx

问题是,如何将 TestPersonResources 表中的“idx”列的名称更改为 Lcid?

我尝试查看此示例 http:// /code.google.com/p/codeconform/source/browse/ConfOrm/ConfOrm.UsageExamples/ComponentAsDictionaryKey/Demo.cs

但我不能似乎将其应用于我的问题。

提前致谢!

I'm having a problem mapping to IDictionary using the new Loquacious configuration.

Here's the class:

public class Person
{
    public Person()
    {
        Description = new Dictionary<int, string>();
    }

    public virtual int Id { get; set; }

    // can be in various languages
    public virtual IDictionary<int, string> Resources { get; set; }
}

public class PersonResource
{
    public virtual string Description { get; set; }
}

Here's the mapping:

public class TestPersonMap : ClassMapping<TestPerson>
{
    Table("TestPersons");

    Id(c => c.Id, m => m.Generator(Generators.HighLow, gm => gm.Params(new { max_low = 1000 })));

    Map(c => c.Resources, mpm =>
                                {
                        mpm.Table("TestPersonResources");
                        mpm.Key(km => km.Column("Id"));
                     },
            mkr => mkr.Component(cem => cem.Property(p => p.Description)));

This produces a table in the database like this:

TestPersons
-----------
Id

TestPersonResources
-------------------
Id
Description
idx

The question is, how do I change the name of the 'idx' column in the TestPersonResources table to Lcid?

I tried looking at this example http://code.google.com/p/codeconform/source/browse/ConfOrm/ConfOrm.UsageExamples/ComponentAsDictionaryKey/Demo.cs

But I can't seem to apply it to my problem.

Thanks in advance!

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

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

发布评论

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

评论(1

萌化 2024-12-10 15:59:17

经过一番折腾并仔细研究 NHibernate 源代码后,我想我终于让它工作了。这就是我所做的:

Map(c => c.Resources, mpm =>
                            {
                    mpm.Key(km => km.Column("Id"));
                    mpm.Table("TestPersonResources");
                },
            mkr => mkr.Element(mkm => mkm.Column("Lcid")),
            cer => cer.Component(cem => cem.Property(p => p.Description, pm => pm.Length(100))));

After messing around and looking harder at the NHibernate source code, I think I finally got it working. Here's what I did:

Map(c => c.Resources, mpm =>
                            {
                    mpm.Key(km => km.Column("Id"));
                    mpm.Table("TestPersonResources");
                },
            mkr => mkr.Element(mkm => mkm.Column("Lcid")),
            cer => cer.Component(cem => cem.Property(p => p.Description, pm => pm.Length(100))));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文