Override for fluent NHibernate for long text strings nvarchar(MAX) not nvarchar(255)

前端 未结 6 1662
时光说笑
时光说笑 2020-12-09 07:26

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

6条回答
  •  忘掉有多难
    2020-12-09 08:13

    Hi I came across this Question, with the same problem. I have an slightly safer way of doing it as I don't want all string fields to have 10000 chars by default.

    Firstly I register fluent nhibernate with some overrides

    ...//snip
    ....Mappings(m => m.AutoMappings.Add(
                        AutoMap.AssemblyOf()
                         //Use my mapping overrides here 
                        .UseOverridesFromAssemblyOf()
                        .Conventions.Add(new MyConventions()).IgnoreBase
                    ))
    

    My Mapping override class looks like this:

    public class MyMappingOverride : IAutoMappingOverride {
           public void Override(AutoMapping mapping) {
               mapping.Map(x => x.LongName).Length(765);
           }
    }
    

    This is only required for small subset of entities with long text values. Maybe some else will find this useful?

提交回复
热议问题