2011-09-08 202 views
2

我有一個問題映射到IDictionary使用新的Loquacious配置。NHibernate 3.2映射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; } 
} 

這裏的映射:

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

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

的問題是,我該怎麼辦:

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

這在這樣的數據庫生成一個表將TestPersonResources表中'idx'列的名稱更改爲Lcid?

我試圖尋找這個例子http://code.google.com/p/codeconform/source/browse/ConfOrm/ConfOrm.UsageExamples/ComponentAsDictionaryKey/Demo.cs

但我似乎無法將它應用到我的問題。

在此先感謝!

回答

2

在搞亂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)))); 
+0

感謝分享,這正是我所需要的。至少保存了一個小時的生命:-) – Dav

相關問題