为什么流利NHibernate忽略我对组件的唯一约束? [英] Why is Fluent NHibernate ignoring my unique constraint on a component?

查看:164
本文介绍了为什么流利NHibernate忽略我对组件的唯一约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的地图中,我有:

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

HBM的相关输出是

 < component name =ExposureKeyinsert =trueupdate =trueoptimistic-lock =trueclass =Some.Namespace.CreditExposureKey,Some.Namespace,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = aaaaaaaaaaaaaaaa> 
< property name =AsOfDatetype =System.DateTime,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089>
< column name =AsOfDatenot-null =true/>
< / property>
< property name =ExposureIdtype =System.String,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089>
< column name =ExposureIdlength =30not-null =true/>
< / property>
< / component>

显然缺少 unique =true组件定义。



为什么会发生这种情况?

解决方案

流利NHibernate的版本?根据

 <$ c (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映射文件没有(可能是一个小错误)。


In my map I have:

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

The relevant output from the HBM is

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

which is clearly missing unique="true" from the component definition.

Why is this happening?

解决方案

Are you using the latest version of Fluent NHibernate? According to James Gregory (Fluent NHibernate contributor), it should work.

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

It would also be good to check if the generated SQL actually has the Unique property set even if the hbm mapping files do not (could be a small bug).

这篇关于为什么流利NHibernate忽略我对组件的唯一约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆