-
Notifications
You must be signed in to change notification settings - Fork 43
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
Class property Context appears to be defined using the incorrect type of string vs DataServiceContext #331
Comments
Related issue: #297 |
This is a known issue. The root issue is that the If your schema has an entity type with a property called Regarding |
The right workaround is to rename the generated property to something else, e.g. rename the [global::Microsoft.OData.Client.OriginalNameAttribute("Context")]
public virtual string ContextFoo
{
// ...
} You can rename the property to anything else, the important thing is that value of the The downside with this workaround is that you'll have to repeat this process each time you re-generate the code. One we way we could address this issue without breaking changes is adding a flag in the UI that lets the user decide whether the client should provide alternative names to properties that may conflict with existing built-in properties. |
The approach these days infrequently uses UI given that DEVOPS pipelines are more likely to be the way forward. (We use the DEVOPS pipeline to call CLI tools that generate the client proxies.) Some form of configuration in terms of "alternative names to properties" as provided to CLI tools is more important. |
When generating client proxies the variable _Context as defined in the C# proxy for a entity can result in compile time errors.
To reproduce the problem, the OData metadata being used is that for Microsoft Dynamics HR. In this case all types and all bound actions are selected for generation. The following is the URL I was using with the some tenant id being that relevant for my scenario. A custom header was used to specify the bearer token for authentication purposes. I have attached the metadata as a text file to save you the trouble of going to the service end point.
eg.
https://aos-rts-sf-c8d2e0b7ff3-prod-westeurope.hr.talent.dynamics.com/namespaces/some tenant id/data
In particular the following two compile time errors are created:
CS1061: 'string' does not contain a definition for 'EntityTracker' and no accessible extension method 'EntityTracker' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
CS1503: Argument 1: cannot convert from 'string' to 'Microsoft.OData.Client.DataServiceContext'
and these occur with the entity type
<EntityType Name="EssWorkflowWorkItem">
where the bound action "complete" results in generation of the codeOn inspection the property Context appears to be type string but should be type DataServiceContext. The following snippet is the generated fragment.
There is also the definition of a property ContextString which I believe to be causing some confusion in the template.
[metadata.txt](https://github.com/OData/ODataConne
metadata.txt
ctedService/files/10345616/metadata.txt)
At this point the workaround for me has been to alter the generated code such that property _Context is defined as DataServiceContext. viz.
This would point to some error in the T4 template caused by the confusion between Context and ContextString
VisualStudio Version v17.4.3
Microsoft.Odata.Client v7.13.x
metadata.txt
The text was updated successfully, but these errors were encountered: