覆盖FluentNHibernate自动映射

时间:2011-09-10 00:32:34

标签: fluent automapping fluent-nhibernate-mapping

我需要更改默认FluentNHibernate Automapping

假设的下一个类数据类型
public class plaparte
{
public virtual int id { get; private set; }
public virtual int vivos { get; set; }
public virtual int lesionados { get; set; }
public virtual int quemados { get; set; }
public virtual int muertos { get; set; }
public virtual int otros { get; set; }
public virtual string colaboracion { get; set; }
public virtual decimal hectareas { get; set; }
public virtual string reconocimiento { get; set; }
public virtual string disposiciones { get; set; }
public virtual plaserv plaserv { get; set; }
}
}

我只需要在此类中将字符串类型转换为数据库中的TEXT 如果我改变

public virtual string[] reconocimiento { get; set; }

FluentNHibernate采用BLOB数据类型

我能做点什么?

public class plaparteMappingOverride : IAutoMappingOverride<plaparte>
{
public void Override(AutoMapping<plaparte> mapping)
{
  Map(x => x.disposiciones).CustomSqlTypeIs("TEXT");
}
}

1 个答案:

答案 0 :(得分:1)

解决我正在使用的问题:

using System.ComponentModel.DataAnnotations;
...
public class plaparte
{
...
[StringLength(4000)]
public virtual string disposiciones { get; set; }

创建TEXT字段

[更新]

对于工作,我需要创建下一个课程

class StringLengthConvention : AttributePropertyConvention<StringLengthAttribute>
{
    protected override void Apply(StringLengthAttribute attribute, IPropertyInstance instance)
    {
        instance.Length(attribute.MaximumLength);
    }
}

也需要添加约定Fluent automap 像

    static AutoPersistenceModel CreateAutomappings()
    {
        return AutoMap.AssemblyOf<plaparte>(new mapAutomapConfiguration())
            .Conventions.Setup(c =>
            {
                c.Add<StringLengthConvention>();
            });
    }