locked
Updating an Existing Data Model - Exception thrown by context.DataModel.Synchronize() RRS feed

  • Question

  • Going on with the weird exceptions (or some caused by my not knowing how to do it properly). I've got the piece of code below:

    NavigationProperty subjNavProp = new NavigationProperty
                        {
                            Name = "hasAnsprechpartner",                       
                        };
                        NavigationProperty objNavProp = new NavigationProperty
                        {
                            Name = "IsAnsprechpartnerFor",
                        };
                        resourceTypePerson.NavigationProperties.Add(objNavProp);
                        resourceTypeThema.NavigationProperties.Add(subjNavProp);
                
    
                        // The association does not exist yet, so create it
                        assocTypeAp = new Association
                        {
                            Name = "Ansprechpartner",
                            SubjectMultiplicity = AssociationEndMultiplicity.One,
                            ObjectMultiplicity = AssociationEndMultiplicity.One
                        };
                        assocTypeAp.SubjectNavigationProperty = subjNavProp;
                        assocTypeAp.ObjectNavigationProperty = objNavProp;
    
                        context.DataModel.Synchronize();

    Running it throws the following exception at the last line:
    Association with Id [be899a57-f561-4851-95d2-850574ba65b4], Name [Ansprechpartner] is attached to a navigation property with Id [992af558-21c7-4052-880a-ca5b2caf07b6], Name [hasAnsprechpartner] that is not a part of this DataModel.

    Umm....yea...clearly it is not part of the DataModel because I am just adding it! Calling Synchronize just after creating the Navigation Properties throws an exception that they are not used in any associations. I'm kind of confuse, would really appreciate some help with this one.

    Cheers

    WizMan

    Wednesday, March 21, 2012 5:45 PM

Answers

  • No, association between two entities in separate module is not supported in Zentity. On doing this it will raise an exception of type ModelItemValidationException with ValidationExceptionOtherEndNotInModel message.

    As given in the .chm help file:-

    An association is considered to be in the module if both its object and subject navigation properties are present in the same module.The navigation property at the other end must be one of those in the same module.

    Please mark it as answer if this helps you.

    Thanks!

    • Proposed as answer by Kalnemi Thursday, March 22, 2012 3:35 PM
    • Marked as answer by WizMan Thursday, March 22, 2012 3:55 PM
    Thursday, March 22, 2012 3:35 PM

All replies

  • The cause of this exception is that one of the end resources is not found in the model. 

    Also, looking on your code I am sure that you will get another exception as One-to-One association is not support in Zentity. The validation will fail.

    good luck!

    • Proposed as answer by Kalnemi Thursday, March 22, 2012 7:29 AM
    Thursday, March 22, 2012 7:29 AM
  • Hmm, the end resources are provided using the following code:

     DataModelModule coreModule = context.DataModel.Modules.Where(tuple => tuple.NameSpace == "MyModel.Model").FirstOrDefault();
                    if (null == coreModule)
                        return;
                    // Get the external resource type (Person)
                    ResourceType resourceTypePerson = context.DataModel.Modules["Zentity.ScholarlyWorks"].ResourceTypes["Person"];
                    ResourceType resourceTypeThema = coreModule.ResourceTypes["Thema"];

    That is, I am trying to create a new Association between two entities in two separate modules. I'm not sure if that is supported though. If not, then it would explain the exception. Could you confirm this please Kalnemi? It would probably spare me the effort of trying harder :o) Thanks!

    Cheers

    WizMan

    Thursday, March 22, 2012 2:28 PM
  • No, association between two entities in separate module is not supported in Zentity. On doing this it will raise an exception of type ModelItemValidationException with ValidationExceptionOtherEndNotInModel message.

    As given in the .chm help file:-

    An association is considered to be in the module if both its object and subject navigation properties are present in the same module.The navigation property at the other end must be one of those in the same module.

    Please mark it as answer if this helps you.

    Thanks!

    • Proposed as answer by Kalnemi Thursday, March 22, 2012 3:35 PM
    • Marked as answer by WizMan Thursday, March 22, 2012 3:55 PM
    Thursday, March 22, 2012 3:35 PM