开发者

Element column length isn't respected when auto mapping a dictionary using Fluent NHibernate

开发者 https://www.devze.com 2023-03-03 14:03 出处:网络
I\'m mapping a dictionary using FluentNHibernate like this: HasMany<MyEntity>(n => n.MyDictionary)

I'm mapping a dictionary using FluentNHibernate like this:

HasMany<MyEntity>(n => n.MyDictionary)
    .AsMap<string>(
        index => index.Column("LCID").Type<int>(),
        element => element.Column("Value").Type<string>().Length(1000)
    .Cascade.AllDeleteOrphan();

As you can see, I'm specifying a column length for the element column 'Value'.

However, the specified element column length isn't respected; when I look at the exported database schema (I'm generating the database from my mappings) the element column is mapped as nvarchar(255).

The generated HBM seems to be correct:开发者_如何学Python

<map table="MyDictionary_Values" name="MyDictionary" mutable="true"
     cascade="all-delete-orphan">
    <key>
        <column name="MyDictionary_id"/>
    </key>
    <index type="int">
        <column name="LCID"/>
    </index>
    <element type="string" length="1000">
        <column name="Value"/>
    </element>
</map>

Here's the incorrect DDL:

create table MyDictionary_Values
(
    MyDictionary_Id INT not null,

    Value NVARCHAR(255) null,

    LCID INT not null,
    primary key (MyDictionary_Id, LCID)
)

Is this a bug in NHibernate or am I doing something wrong?


Use this walkthrough :

HasMany<MyEntity>(n => n.MyDictionary)
  .AsMap<string>(
      index => index.Column("LCID").Type<int>(),
      element => element.Columns.Clear().Columns.Add("Value", col => col.Length(1000))
  .Cascade.AllDeleteOrphan();
0

精彩评论

暂无评论...
验证码 换一张
取 消