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();
精彩评论