2017-06-20 3 views
0

Ich habe diese Konvention:Map Eigenschaft als Wert (nicht Verband) für die Verwendung mit IUserType Umwandlung

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 }; 
    // ... 
} 

, die gut funktioniert, wenn ich eine Überschreibung mapping.Map(x=>x.MyProperty) angeben, aber ohne sie ich sehe eine Ausnahme An association from the table X refers to an unmapped class: NotMappedType. Meine Eigenschaft wird als eine Assoziation behandelt (also nie an die Konvention übergeben), aber ich möchte, dass sie als normale Werteigenschaft behandelt wird.

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

Wie kann ich es ohne die Überschreibung machen?

Antwort

1

Ich habe XmlSerializedConvention geändert, um Schnittstelle IUserTypeConvention zu implementieren (ohne Implementierungsänderungen) und jetzt funktioniert es gut.

Verwandte Themen