本文介绍了NHibernate 3.2通过代码映射IDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用新的Loquacious配置映射到IDictionary时遇到问题.
I'm having a problem mapping to IDictionary using the new Loquacious configuration.
这是课程:
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)));
这将在数据库中生成一个表,如下所示:
This produces a table in the database like this:
TestPersons
-----------
Id
TestPersonResources
-------------------
Id
Description
idx
问题是,如何将TestPersonResources表中'idx'列的名称更改为Lcid?
The question is, how do I change the name of the 'idx' column in the TestPersonResources table to Lcid?
但是我似乎无法将其应用于我的问题.
But I can't seem to apply it to my problem.
提前谢谢!
推荐答案
在弄乱并仔细查看NHibernate源代码后,我认为我终于使它工作了.这是我所做的:
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))));
这篇关于NHibernate 3.2通过代码映射IDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!