0
我有以下模式:無效的索引4 = 4
public class ExchangeRate
{
[Key, Column(Order = 1)]
public virtual int JobId { get; set; }
[Key, Column(Order = 2), MaxLength(3)]
public virtual Currency Source { get; set; }
[Key, Column(Order = 3), MaxLength(3)]
public virtual Currency Target { get; set; }
public virtual decimal Rate { get; set; }
public virtual Job Job { get; set; }
public override bool Equals(object obj)
{
if (obj == null)
return false;
var t = obj as ExchangeRate;
if (t == null)
return false;
if (this.Job == t.Job & this.Source == t.Source && this.Target == t.Target)
return true;
return false;
}
public override int GetHashCode()
{
return (this.JobId + "|" + this.Source + "|" + this.Target).GetHashCode();
}
我有以下自動映射控制裝置:
public void Override(AutoMapping<ExchangeRate> mapping)
{
mapping.Map(x => x.Source).CustomType<GenericEnumMapper<Currency>>();
mapping.Map(x => x.Target).CustomType<GenericEnumMapper<Currency>>();
// Define the composite key
mapping.CompositeId()
.KeyProperty(e => e.JobId, "JobId")
.KeyProperty(e => e.Source)
.KeyProperty(e => e.Target);
}
我已經出口到下面導出的映射文件嘗試並幫助診斷問題:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="JFS.Data.Model.ExchangeRate, JFS.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="ExchangeRates">
<composite-id>
<key-property name="JobId" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="JobId" />
</key-property>
<key-property name="Source" type="FluentNHibernate.Mapping.GenericEnumMapper`1[[JFS.Data.Currency, JFS.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], FluentNHibernate, Version=1.3.0.717, Culture=neutral, PublicKeyToken=8aa435e3cb308880">
<column name="Source" />
</key-property>
<key-property name="Target" type="FluentNHibernate.Mapping.GenericEnumMapper`1[[JFS.Data.Currency, JFS.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], FluentNHibernate, Version=1.3.0.717, Culture=neutral, PublicKeyToken=8aa435e3cb308880">
<column name="Target" />
</key-property>
</composite-id>
<property name="Source" type="FluentNHibernate.Mapping.GenericEnumMapper`1[[JFS.Data.Currency, JFS.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], FluentNHibernate, Version=1.3.0.717, Culture=neutral, PublicKeyToken=8aa435e3cb308880">
<column name="Source" />
</property>
<property name="Target" type="FluentNHibernate.Mapping.GenericEnumMapper`1[[JFS.Data.Currency, JFS.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], FluentNHibernate, Version=1.3.0.717, Culture=neutral, PublicKeyToken=8aa435e3cb308880">
<column name="Target" />
</property>
<property name="Rate" type="System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Rate" />
</property>
<many-to-one class="JFS.Data.Model.Job, JFS.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Job">
<column name="JobId" />
</many-to-one>
</class>
</hibernate-mapping>
我一直在撕掉我的頭髮現在正試圖解決這個問題,但沒有成功。我閱讀過很多文章,並且未能成功應用任何解決方案。我對NHibernate相對比較陌生,並且熱衷於開始使用它,但到目前爲止,已經證明了一個非常陡峭的學習曲線來啓動和運行項目。任何意見的解決方案和解釋的建議,將不勝感激。
謝謝,似乎已經克服了這種例外。我現在有一個新的例外,也許我應該發佈一個新的問題? 來自表ExchangeRates的關聯指向未映射的類:JFS.Data.Currency – ProNotion 2012-03-02 20:36:41
什麼是GenericEnumMapper'。 '貨幣'是你想用於'源'和'目標'的枚舉嗎? –
2012-03-02 20:55:10
是貨幣是來源和目標的枚舉。 GenericEnumMapper允許我保存枚舉的字符串值,而不是數據庫中的整數表示。 – ProNotion 2012-03-02 21:23:03