locked
metadata Error TypeMismatchRelationshipConstraint in the referential constraint 'Fred' RRS feed

  • Question

  • Creating an association between tables creates a Metadata error. Removing the association clears the error from the metadata.

    The association is a Foreign Key in the database. 

    The association is based on a "Main table that holds all possible selection"; "A Link Table that holds values which have been selected from the Main table and are application"

    The Error is "An IEdmModel instance was found that failed validation. The following errors were reported: TypeMismatchRelationshipConstraint : The types of all properties in the dependent role of a referential constraint must be the same as the corresponding property types in the principal role. The type of property 'RangeId' on entity 'EDM.Draft.Product' does not match the type of property 'ProductTypeCode' on entity 'RangeType' in the referential constraint 'Fred'. TypeMismatchRelationshipConstraint : The types of all properties in the dependent role of a referential constraint must be the same as the corresponding property types in the principal role. The type of property 'ProductTypeCode' on entity 'EDM.Draft.Product' does not match the type of property 'RangeId' on entity 'RangeType' in the referential constraint 'Fred'. "

    From http://dotnetinside.com/ru/framework/WCF+Data+Services/Microsoft.Data.Edm/ValidationRules I can see where the "Fred" is originating but I don't understand why the error is being raised.

          if (!navigationProperty.DependentProperties.ElementAtOrDefault(i).Type.Definition.IsEquivalentTo(source.ElementAtOrDefault(i).Type.Definition))
    {
    string errorMessage = Strings.EdmModel_Validator_Semantic_TypeMismatchRelationshipConstraint(navigationProperty.DependentProperties.ToList<IEdmStructuralProperty>()[i].Name, navigationProperty.DeclaringEntityType().FullName(), source.ToList<IEdmStructuralProperty>()[i].Name, edmEntityType.Name, "Fred");
    context
    .AddError(navigationProperty.Location(), EdmErrorCode.TypeMismatchRelationshipConstraint, errorMessage);
         

    Thanks

    ShaneC

    Thursday, October 31, 2013 8:59 AM

All replies

  • Hello,

    >>I don't understand why the error is being raised.

    We can the judge condition:

    if(!navigationProperty.DependentProperties.ElementAtOrDefault(i).Type.Definition.IsEquivalentTo(source.ElementAtOrDefault(i).Type.Definition))

    When the two compared types are different, then it will throw the error message.

    And with the error message, we can see that the type of property 'ProductTypeCode' on entity 'EDM.Draft.Product' does not match the type of property 'RangeId' on entity 'RangeType'.

    So it seems that they need to be the same type.

    However, I am strange that why the property 'ProductTypeCode' needs to match property 'RangeId'.

    Could you please share the more detail table structure so that we can help you better?

    Or you can upload your program to skydive.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 1, 2013 6:06 AM
    Moderator
  • Thanks Fred, I hope the below is enough.

    The Edmx file is generated from an SQL2008 database. The only changes are then creation of the two complex types and putting them on the entities.

    Edmx runtime text files

    The <edmx:Runtime> is present in each file. NoError.txt (that which works) and Error.txt (that which does not)

    From the Entity RangeType

              <Property Name="RangeId" Type="Int32" Nullable="false" />
              <Property Name="ProductTypeCode" Type="String" Nullable="false" MaxLength="2" FixedLength="false" Unicode="true" />

    From the Entity Product

              <Property Name="RangeId" Type="Int32" Nullable="false" />
              <Property Name="ColourId" Type="Int32" Nullable="false" />
              <Property Name="ProductTypeCode" Type="String" Nullable="false" MaxLength="2" FixedLength="false" Unicode="true" />

    When the "Association/Navigation" is added the file Differences are

    <AssociationSet Name="RangeTypeProduct" Association="EDM.Draft.RangeTypeProduct"> <End Role="RangeType" EntitySet="RangeTypes" /> <End Role="Product" EntitySet="Products" /> </AssociationSet> <NavigationProperty Name="RangeType" Relationship="EDM.Draft.RangeTypeProduct" FromRole="Product" ToRole="RangeType" /> <NavigationProperty Name="Products" Relationship="EDM.Draft.RangeTypeProduct" FromRole="RangeType" ToRole="Product" />

    <Association Name="RangeTypeProduct"> <End Type="EDM.Draft.RangeType" Role="RangeType" Multiplicity="1" /> <End Type="EDM.Draft.Product" Role="Product" Multiplicity="*" /> <ReferentialConstraint> <Principal Role="RangeType"> <PropertyRef Name="RangeId" /> <PropertyRef Name="ProductTypeCode" /> </Principal> <Dependent Role="Product"> <PropertyRef Name="RangeId" /> <PropertyRef Name="ProductTypeCode" /> </Dependent> </ReferentialConstraint> </Association>

    The project references (both NuGet)

    Microsoft.Data.Service 5.6.0

    EntityFramework 5.0.0

    on the svc

    Factory="System.ServiceModel.Activation.WebServiceHostFactory, System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35


    • Edited by shanec112 Friday, November 1, 2013 7:01 AM More Info
    Friday, November 1, 2013 6:52 AM
  • >> The only changes are then creation of the two complex types and putting them on the entities.

    Does it mean that you do the moderation by manually?


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 1, 2013 9:42 AM
    Moderator
  • Don't understand what you mean.

    Manually by editing the file ? No.

    Manually amend the conceptual model diagram to have complex types and redo the entity mapping for them ? yes

    .....

    The Differences above are what is shown in the projects source control between the version of the edmx that correctly generates a $metadata and the version that generates a $metadata with the "FRED" error.

    Both versions of the OData Service "Work" ! The Navigation properties which are listed above work when doing a query even if the $metadata shows an error.

    The reason why I would like to get the $metadata to also work is that I am using the WCF Client to generate a proxy class on the client. And then a T4 script to wrap the proxy up for presentation.

    .....

    The $metadata error occurs on association between RangeType & Products additionally on RangeFactor2 & Products and also RangeWeight & Products.

    The $metadata error occurs when the project is built on a Windows 7 install and a Windows 8.1 install.

    • Edited by shanec112 Friday, November 1, 2013 10:39 AM
    Friday, November 1, 2013 10:06 AM
  • >>The $metadata error occurs when the project is built on a Windows 7 install and a Windows 8.1 install.

    Does it mean that it will work fine when it is bulit on Win8.

    Thursday, November 21, 2013 9:55 AM
  • Don't know, have not got a Windows 8 build that I can test on !
    Thursday, November 21, 2013 9:58 AM