问题
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!
回答1:
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))));
来源:https://stackoverflow.com/questions/7354483/nhibernate-3-2-mapping-idictionary-by-code