我有这个惯例:
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; }
如何在没有覆盖的情况下使其工作?
答案 0 :(得分:1)
我更改了XmlSerializedConvention
以实现接口IUserTypeConvention
(没有实现更改),现在效果很好。