I have a 1-to-many association between a Mandate which holds a collection of OpenPosition entities. Note that on OpenPosition I have a foreign key to Mandate and in the model it is decorated with the ForeignKeyAssociation Attribute.
Then I use a WCF DataService for sending data to the client. But the metadata generated is incomplete. See :
<
Association
Name
=
"OpenPosition_Mandate_Mandate_OpenPositions"
>
<
End
Type
=
"DirectDebitModel.Mandate"
Multiplicity
=
"0..1"
Role
=
"Mandate_OpenPositions"
/>
<
End
Type
=
"DirectDebitModel.OpenPosition"
Multiplicity
=
"*"
Role
=
"OpenPosition_Mandate"
/>
</
Association
>
<
EntityContainer
Name
=
"FluentModel"
m:IsDefaultEntityContainer
=
"true"
>
<
EntitySet
Name
=
"OpenPositions"
EntityType
=
"DirectDebitModel.OpenPosition"
/>
<
EntitySet
Name
=
"Mandates"
EntityType
=
"DirectDebitModel.Mandate"
/>
<
AssociationSet
Name
=
"OpenPosition_Mandate"
Association
=
"DirectDebitModel.OpenPosition_Mandate_Mandate_OpenPositions"
>
<
End
Role
=
"OpenPosition_Mandate"
EntitySet
=
"OpenPositions"
/>
<
End
Role
=
"Mandate_OpenPositions"
EntitySet
=
"Mandates"
/>
</
AssociationSet
>
</
EntityContainer
>
The referentialConstraint node inside the Association node is missing ! Normally this is generated when the .HasForeignKey() method is used in the Fluent model (with EntityFramework). I haven't found such a method in the OpenAccess API. But I thought that the ForeignKeyAssociation attribute would be enough.
Telerik openaccess data service implementation seems to ignore completely this feature.
Is this a missing feature or am I doing something wrong ?
10 Answers, 1 is accepted
The ReferentialConstraint node in the metadata of services based on EF is a side effect of the metadata provider they use. In general this node is not part of the oData metadata officially. You could check this with some of the sample services like this one.
Also most of the clients do not respect this node, that's why our service metadata provider do not generate this node.
Do you face any issues because of the missing node? If you do we can try to find a way how workaround it.
I hope this helps. Please do not hesitate to get back to us with any questions.
Kaloyan Nikolov
Telerik
Thanks for you reply. I hope you can help me. Actually, ReferentialConstraint IS part of the official ODATA specification since V3. See this link:
http://www.odata.org/documentation/odata-v3-documentation/common-schema-definition-language-csdl/#104_The_edmReferentialConstraint_Element
The thing is that I desperately need this node to be part of the metadata, because I use breezejs on the client side to help with data management in JavaScript and this library relies on the referential constraint node to build navigation properties.
So far I've been unsuccessful at adding this node to the metadata using OpenAccess (works fine with EF but my company uses OpenAccess). Do you think you could help ?
We use a custom implementation of the IDataServiceMetadataProvider interface to produce the metadata needed. The property we should set in order to get this element is ResourceAssociationType.ReferentialConstraint is internal and unfortunately we don't have access to it. It seems that only Microsoft is able to produce this metadata easily. You probably could use reflection to set those internal members but this will not guarantee that it will work in the next version. We cannot support this approach out of the box.
We will try to find better way to deal with the situation. I'll let you know when we have more information.
Kaloyan Nikolov
Telerik
Do you think you can come up with a solution for me ?
We will probably have to find a way to support this element anyway, since it would make our oData support better and more feature complete. At this point we are still unsure what would be the best way to tackle the limitation Microsoft has imposed, but we will work on that during the next few days and we will let you know once we have a solution or a workaround that can be applied on your side.
Regards,
Telerik
Could I have an update on this? Have you found a workaround for adding the missing node to the metadata ?
Thanks
So far we have not found a way to set the metadata that you are looking for and there will be no changes in behaviour for the upcoming Q3 2013 release.
I am not sure if we will be able to implement this in the future. Given the limitations of the API that Microsoft have imposed I do not see a way to overcome this issue even given the source code of the OpenAccessMetadataProvider.
I am sorry for the inconvenience. If there is any progress that can resolve the issue you are experiencing I will make sure to contact you with the latest information.
Regards,
Viktor Zhivkov
Telerik
In order to assist you could you describe in more details your scenario. What do you mean by "refreshing data"? What kind of application you refer, is this a service as the current thread is bound to service issues?
Regards,
Kaloyan Nikolov
Telerik