开发者

NHibernate 3.2 Mapping IDictionary By Code

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 i开发者_如何转开发nt 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!


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))));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜