问题描述
当您在 fluent NHibernate 中设置字符串值时,它总是将 DB 值设置为 Nvarchar(255),我需要存储相当多的基于用户输入的长字符串,而 255 是不切实际的.
补充一点,这是自动映射器的一个问题,因为我正在使用流畅的 NHibernate 来构建数据库.
添加此约定会将字符串属性的默认长度设置为 10000.正如其他人所指出的,这将是一个 nvarchar(max) 列.
public class StringColumnLengthConvention : IPropertyConvention, IPropertyConventionAcceptance{public void Accept(IAcceptanceCriteriacriteria){标准.期望(x => x.Type == typeof(string)).Expect(x => x.Length == 0);}公共无效应用(IPropertyInstance 实例){实例长度(10000);}}
可以像这样将约定添加到自动映射配置中:
Fluently.Configure().Mappings(m =>m.AutoMappings.Add( AutoMap.AssemblyOf().Conventions.Add()))
有关详细信息,请参阅 Fluent NHibernate wiki 中的约定.>
When ever you set a string value in fluent NHibernate it alwasy sets the DB vales to Nvarchar(255), I need to store quite a lot of long string which are based on user inputs and 255 is impractical.
Just to add this is an issue with the automapper as I am using fluent NHibernate to build the database.
Adding this convention will set the default length for string properties to 10000. As others have noted, this will be a nvarchar(max) column.
public class StringColumnLengthConvention : IPropertyConvention, IPropertyConventionAcceptance
{
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(x => x.Type == typeof(string)).Expect(x => x.Length == 0);
}
public void Apply(IPropertyInstance instance)
{
instance.Length(10000);
}
}
Conventions can be added to an automap configuration like this:
Fluently.Configure()
.Mappings( m =>
m.AutoMappings.Add( AutoMap.AssemblyOf<Foo>()
.Conventions.Add<StringColumnLengthConvention >()))
For more information, see Conventions in the Fluent NHibernate wiki.
这篇关于覆盖长文本字符串的流畅 NHibernate nvarchar(MAX) 而不是 nvarchar(255)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!