0

I'm trying hard to find a solution to be able to override the automapping of my entity.

The flow of execution is that AutoMapping (using conventions) occurs first and then mapping overrides are executed.

My entity "Signature" is already mapped by automapper (do not confuse with Automapper library!) and I want to change the db type of some columns.

If I do something like this:

public class SignatureMap : IAutoMappingOverride<Signature>
{
    public void Override(AutoMapping<Signature> mapping)
    {
        mapping.Map(x => x.SignType).CustomSqlType("character varying");
        mapping.Map(x => x.Status).CustomSqlType("integer").Nullable();
    }
} 

I get NHibernate errors with NpgsqlParameterCollection (index out of range) when trying to execute an insert to the table.

This probably occurs because the mapping.Map function just adds another mapping to the collection instead of overriding one that already exists (I examined the FluentNHibernate source code).

What is the proper way to override the Sql type using IAutoMappingOverride ?

4

1 回答 1

1

您使用的覆盖语法没有任何问题,请确保您:
1)在配置中实际引用您的覆盖映射:.UseOverridesFromAssemblyOf<SignatureMap>();
2)验证 NHibernate 是否按预期处理您的数据库模式。您可以为此使用类似的东西new SchemaExport(config).Create(true, false);,这会将 sql 输出到控制台。

如果 1 和 2 都可以,那么问题可能出在您的插入代码中。

于 2013-03-09T15:58:22.127 回答