映射 属性 作为一个值(不是关联)用于 IUserType 转换

Map property as a value (not association) for using with IUserType conversion

我有这个约定:

public class XmlSerializedConvention : IPropertyConvention, IPropertyConventionAcceptance
{
    public void Apply(IPropertyInstance instance)
    {
        instance.CustomType(typeof(XmlSerializedType<>).MakeGenericType(instance.Property.PropertyType));
    }

    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(
            x => Attribute.IsDefined(x.Property.MemberInfo, typeof(XmlSerializedDbMappingAttribute)));
    }
}

public class XmlSerializedType<T> : IUserType
{
    public bool IsMutable => true;

    public Type ReturnedType => typeof(T);

    public SqlType[] SqlTypes => new[] { NHibernateUtil.String.SqlType };
    // ...
}

当我指定覆盖 mapping.Map(x=>x.MyProperty) 时效果很好,但没有它我会看到异常 An association from the table X refers to an unmapped class: NotMappedType。我的 属性 被视为关联(因此从未传递给约定)但我希望它被视为正常值 属性.

[XmlSerializedDbMapping]
public NotMappedType MyProperty { get; set; }

如何在没有覆盖的情况下使其工作?

我更改了 XmlSerializedConvention 以实现接口 IUserTypeConvention(没有实现更改),现在它运行良好。