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

الإجابة Updating an Existing Data Model - Exception thrown by context.DataModel.Synchronize()

  • Mittwoch, 21. März 2012 17:45
     
      Enthält Code

    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

Alle Antworten

  • Donnerstag, 22. März 2012 07:29
     
     Vorgeschlagene Antwort

    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!

    • Als Antwort vorgeschlagen Kalnemi Donnerstag, 22. März 2012 07:29
    •  
  • Donnerstag, 22. März 2012 14:28
     
      Enthält Code

    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

  • Donnerstag, 22. März 2012 15:35
     
     Beantwortet

    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!

    • Als Antwort vorgeschlagen Kalnemi Donnerstag, 22. März 2012 15:35
    • Als Antwort markiert WizMan Donnerstag, 22. März 2012 15:55
    •