Fluent nhibernate Fluent NHibernate-覆盖一个特定类上的一个特定属性的类型?

Fluent nhibernate Fluent NHibernate-覆盖一个特定类上的一个特定属性的类型?,fluent-nhibernate,Fluent Nhibernate,我有一个类,它有一个密码属性,我想将它加密存储在数据库中。该属性是一个字符串类型,我有一个自定义类型EncryptedStringType,希望NHibernate使用它将其映射到数据库。以下是我的相关自动映射代码: var mappings = AutoMap.AssemblyOf<Business>() .Where(x=>x.IsSubclassOf(typeof(EntityBase))) .IgnoreBase(typeof(EntityBase))

我有一个类,它有一个密码属性,我想将它加密存储在数据库中。该属性是一个字符串类型,我有一个自定义类型EncryptedStringType,希望NHibernate使用它将其映射到数据库。以下是我的相关自动映射代码:

var mappings = AutoMap.AssemblyOf<Business>()
    .Where(x=>x.IsSubclassOf(typeof(EntityBase)))
    .IgnoreBase(typeof(EntityBase))
    .Conventions.Add
        (
            ConventionBuilder.Id.Always(x =>
                x.GeneratedBy.HiLo(HILO_TABLE, HILO_COLUMN, HILO_MAX_LO)),
            ConventionBuilder.HasMany.Always(x => x.Cascade.AllDeleteOrphan()),
            Table.Is(o => Inflector.Pluralize(o.EntityType.Name)),
            PrimaryKey.Name.Is(o => "Id"),
            ForeignKey.EndsWith("Id"),
            DefaultLazy.Always(),
            DefaultCascade.All()
        );
var-mappings=AutoMap.AssemblyOf()
其中(x=>x.IsSubclassOf(typeof(EntityBase)))
.IgnoreBase(类型(EntityBase))
.Add
(
ConventionBuilder.Id.Always(x=>
x、 .HiLo生成(HiLo_表,HiLo_列,HiLo_MAX_LO)),
ConventionBuilder.HasMany.Always(x=>x.Cascade.AllDeleteOrphan()),
表.Is(o=>definctor.Pluralize(o.EntityType.Name)),
PrimaryKey.Name.Is(o=>“Id”),
ForeignKey.EndsWith(“Id”),
DefaultLazy.Always(),
DefaultCascade.All()
);
但是,我无法理解覆盖业务类的UserPassword属性类型的语法。我想我应该可以用覆盖做一些事情,比如:

mappings.Override<Business>(map=> /* Not sure what to do here */);
mappings.Override(map=>/*不确定在这里做什么*/);

感谢您的帮助。

我自己找到了答案

mappings.Override<Business>(map =>
{
    map.Map(x => x.UserPassword).CustomType<EncryptedStringType>();
});
mappings.Override(映射=>
{
map.map(x=>x.UserPassword).CustomType();
});

您始终可以创建映射覆盖类。仍然可以应用的任何约定都将是,但您基本上可以指定类似于覆盖默认约定的类映射的映射

使用对mappings.Override()的调用,它看起来像:

mappings.Override<Business>(map=>map.Map(x=>x.UserPassword).CustomType(typeof(EncryptedStringType)));
mappings.Override(map=>map.map(x=>x.UserPassword).CustomType(typeof(EncryptedStringType));