开发者

Trying to use Habanero Smooth to create two relationships to an XML defined class

开发者 https://www.devze.com 2023-03-11 11:17 出处:网络
I am trying to use Habanero Smooth to map two relationships to a class which is defined in my ClassDefs.

I am trying to use Habanero Smooth to map two relationships to a class which is defined in my ClassDefs.

Habanero Smooth Class:

    [AutoMapCompulsory]
    [AutoMapOneToMany(ReverseRelationshipName = "TestRules")]
    public virtual Determinand Determinand
    {
        get { return Relationships.GetRelatedObject<Determinand>("Determinand"); }
        set { Relationships.SetRelatedObject("Determinand", value); }
    }

    [AutoMapOneToMany(ReverseRelationshipName = "RelatedTestRules")]
    public virtual Determinand RelatedDeterminand
    {
        get { return Relationships.GetRelatedObject<Determinand>("RelatedDeterminand"); }
        set { Relationships.SetRelatedObject("Relat开发者_C百科edDeterminand", value); }
    }

XML Class :

   <class name="Determinand" assembly="" table="tbdeterminand" displayName="Determinand">
          <property name="DeterminandID" type="Guid" readWriteRule="WriteNew" compulsory="true" />
   </class>

Problem

When I execute my test to validate that my ClassDefs are generated correctly it fails giving me the following error:

Test

            [Test]
            public void Test_ValidateClassDefs()
            {
                //---------------Set up test pack-------------------
                ClassDef.ClassDefs.Add(BOBroker.GetClassDefs());
                //---------------Assert Precondition----------------
                ClassDef.ClassDefs.ShouldNotBeEmpty();
                //---------------Execute Test ----------------------
                var validator = new ClassDefValidator(new DefClassFactory());
                validator.ValidateClassDefs(ClassDef.ClassDefs);
            }

Error

Habanero.Base.Exceptions.InvalidXmlDefinitionException : The relationship 'RelatedDeterminand' could not be loaded because the reverse relationship 'TestRules' defined for the related class 'Determinand' and the relationship 'RelatedDeterminand' defined for the class 'LIMS.BO.TestRule' do not have the same properties defined as the relationship keys - No matching RelProp found for RelatedDeterminandID -> DeterminandID Relationship RelatedDeterminandRelProp 1 RelatedDeterminandID - DeterminandID ReverseRelationship TestRulesRelProp 1 DeterminandID - DeterminandID at Habanero.BO.ClassDefinition.ClassDefValidator.CheckReverseRelationshipRelKeyDefProps(IRelationshipDef relationshipDef, IClassDef relatedClassDef, String reverseRelationshipName, IRelationshipDef reverseRelationshipDef, IClassDef classDef) at Habanero.BO.ClassDefinition.ClassDefValidator.ValidateReverseRelationship(IClassDef classDef, IRelationshipDef relationshipDef, IClassDef relatedClassDef) at Habanero.BO.ClassDefinition.ClassDefValidator.CheckRelationshipsForAClassDef(IDictionary`2 loadedFullPropertyLists, IClassDef classDef, ClassDefCol classDefs) at Habanero.BO.ClassDefinition.ClassDefValidator.CheckRelationships(ClassDefCol classDefs) at Habanero.BO.ClassDefinition.ClassDefValidator.ValidateClassDefs(ClassDefCol classDefCol) at LIMS.Test.BO.TestClassDefValid.Test_ValidateClassDefs() in TestClassDefValid.cs: line 37


OK the fundamental problem is that you have defined your automap relationship the incorrect way.

[AutoMapOneToMany(ReverseRelationshipName = "RelatedTestRules")]
public virtual Determinand RelatedDeterminand

Should be

[AutoMapManyToOne(ReverseRelationshipName = "RelatedTestRules")]
public virtual Determinand RelatedDeterminand

A single relationship e.g. RelatedDeterminand will always be either a OneToOne or a ManyToOne.

The error message could however be much more helpfull.

Please log an issue on http://redmine.habanerowiki.com/projects/show/habanerosmooth to make a more meaningfull error in these cases.

0

精彩评论

暂无评论...
验证码 换一张
取 消