【问题标题】:NHibernate 3.2 Mapping IDictionary By CodeNHibernate 3.2 按代码映射字典
【发布时间】:2012-03-23 03:58:17
【问题描述】:

我在使用新的 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

但我似乎无法将其应用于我的问题。

提前致谢!

【问题讨论】:

    标签: nhibernate nhibernate-mapping nhibernate-mapping-by-code


    【解决方案1】:

    在搞砸并更努力地查看 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))));
    

    【讨论】:

    • 感谢分享,这正是我所需要的。至少挽救了我一个小时的生命:-)
    猜你喜欢
    • 2014-04-02
    • 1970-01-01
    • 1970-01-01
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多