5

在我的地圖我:爲什麼流利NHibernate忽略我對組件的唯一約束?

Component(
    x => x.ExposureKey, 
    m => { 
     m.Map(x => x.AsOfDate).Not.Nullable(); 
     m.Map(x => x.ExposureId).Length(30).Not.Nullable(); 
    } 
).Unique(); 

從HBM相關的輸出是

<component name="ExposureKey" insert="true" update="true" optimistic-lock="true" class="Some.Namespace.CreditExposureKey, Some.Namespace, Version=0.0.0.0, Culture=neutral, PublicKeyToken=aaaaaaaaaaaaaaaa"> 
    <property name="AsOfDate" type="System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 
     <column name="AsOfDate" not-null="true"/> 
    </property> 
    <property name="ExposureId" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> 
     <column name="ExposureId" length="30" not-null="true"/> 
    </property> 
</component> 

這顯然是從component定義缺失unique="true"

這是怎麼發生的?

回答

0

您使用的是最新版本的Fluent NHibernate嗎?根據James Gregory(流利NHibernate的貢獻者),它應該工作。

// Else, try this hack: 
Component(x => x.ExposureKey, m => 
{ 
    m.Map(x => x.AsOfDate).Not.Nullable(); 
    m.Map(x => x.ExposureId).Length(30).Not.Nullable(); 
}).SetAttribute("unique", "true"); 

這也將是很好的檢查,如果生成的SQL卻有Unique屬性設置即使HBM映射文件不(可能是一個小bug)。

+0

我會嘗試一個更新的版本(我正在使用生成685,而目前是694)。我認爲'SetAttribute'已被刪除。生成的SQL沒有'unique'屬性集(並且不應該,因爲它不在映射中!)。 – jason 2010-10-10 21:16:34

+0

已更新至最新版本(694)。仍然沒有去。 – jason 2010-10-10 21:42:02

+0

@Jason:這是奇怪的++,我的VS在家裏正在採取行動。希望在我嘗試在工作中複製此內容(大約12小時)之前,您會得到答案。這是什麼,MSSQL/MySQL? – rebelliard 2010-10-10 23:50:49