Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referential constraint 'Fred' #2888

Open
0xNinshu opened this issue Mar 7, 2024 · 1 comment
Open

Referential constraint 'Fred' #2888

0xNinshu opened this issue Mar 7, 2024 · 1 comment
Assignees
Labels

Comments

@0xNinshu
Copy link

0xNinshu commented Mar 7, 2024

Description

I was attempting to convert a very large CSDL, I ran validation on the parsed document and found an odd issue. It took me a bit to realize that the word 'Fred' had nothing to do with my code or the document I was parsing but has likely been a bug in the code base for about 10 years if the git blame is to be believed.

I attempted to make the fix myself but I don't have the time. It was painful getting a successful build, and I am not familiar enough with the OData spec to say what should be used instead of 'Fred'.

Here is an example set of error messages:

> 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 'contentfileref' on entity 'Microsoft.Dynamics.CRM.webresource' does not match the type of property 'fileattachmentid' on entity 'fileattachment' in the referential constraint 'Fred'.
> Because all dependent properties of the navigation 'ContentFileRef' are nullable, the multiplicity of the principal end must be '0..1'.
> 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 'contentjsonfileref' on entity 'Microsoft.Dynamics.CRM.webresource' does not match the type of property 'fileattachmentid' on entity 'fileattachment' in the referential constraint 'Fred'.

Code Reference

https://github.com/OData/odata.net/blame/57572612f1ff833d395b44e6b2c498d7d0d31890/src/Microsoft.OData.Edm/Validation/ValidationRules.cs#L1614

if (!(dependentType is BadType) && !(principalType is BadType) && !dependentType.IsEquivalentTo(principalType))
{
    string errorMessage = Strings.EdmModel_Validator_Semantic_TypeMismatchRelationshipConstraint(
        navigationProperty.DependentProperties().ToList()[i].Name,
        navigationProperty.DeclaringEntityType().FullName(),
        principalProperties.ToList()[i].Name,
        principalEntityType.Name,
        "Fred"
    );

    context.AddError(navigationProperty.Location(), EdmErrorCode.TypeMismatchRelationshipConstraint, errorMessage);
}

Non-Annotated CSDL

I don't know if this is helpful but this is one of the documents I am working with, it should help with test cases but be warned validating this document takes 7 minutes on my PC.
$metadata.xml

@xuzhg
Copy link
Member

xuzhg commented Mar 11, 2024

"Fred"??? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants