1

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("RelatedDeterminand", 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

Sherwin
  • 13
  • 2

1 Answers1

0

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.

GloryDev
  • 670
  • 5
  • 8
  • Wow, that would be hard to spot if you didn't know what to look for. I guess it is quite obvious that if you define a single relationship on a class it should be a Many-To-One not a One-To-Many, because you are looking at the relationship from that class's perspective. I think it would be vital to get a better error message. You could also add a check to see if the property that you have put the [AutoMapOneToMany] attribute on is at least enumerable. – Mark Whitfeld Jun 07 '11 at 14:45
  • There is a lotta code in smooth to reverse engineer many and single rels so should be really easy for smooth to add this check. – GloryDev Jun 07 '11 at 15:31