本文介绍了为长文本字符串重写流畅的NHibernate nvarchar(MAX)不是nvarchar(255)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你在流利的NHibernate中设置一个字符串值时,它将数据库值设置为Nvarchar(255),我需要存储相当多的基于用户输入的长字符串,并且255是不切实际的。

只要添加这个是automapper的问题,因为我使用流利的NHibernate构建数据库。

解决方案

添加这个约定会将字符串属性的默认长度设置为10000.正如其他人所指出的,这将是一个nvarchar

  public class StringColumnLengthConvention:IPropertyConvention,IPropertyConventionAcceptance 
{
public void Accept(IAcceptanceCriteria< IPropertyInspector>标准)
{
criteria.Expect(x => x.Type == typeof(string))。

public void Apply(IPropertyInstance instance)
{
instance.Length(10000);






约定可以添加到像这样的自动映射配置中:

 流利.Configure()
.Mappings(m =>
m.AutoMappings.Add AutoMap.AssemblyOf< Foo>()
.Conventions.Add< StringColumnLengthConvention>()))

有关更多信息,请参阅Fluent NHibernate wiki中的。 p>

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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:19