odata.net
odata.net copied to clipboard
Context Attribute on Connected Service causes conflict in generated code
When using the Odata Connected Service Plugin for VS to import a metadata document and generate project code for our entities, there is a virtual property added with the POCO name "Context" which conflicts with another property.
Assemblies affected
Which assemblies and versions are known to be affected e.g. OData .Net lib 7.x
Reproduce steps
Attaching a file for the Odata metadata endpoint of a D365 service. This should generate and compile correctly, instead you will see an error expecting an Object instead of "string"
Expected result
The generated code would successfully build
Actual result
Severity Code Description Project File Line Suppression State Error 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?) ConsoleApp1 C:\Users\anschmidt\source\repos\ConsoleApp1\ConsoleApp1\Connected Services\OData Service\Reference.cs 973169 Active
Additional detail
/// <summary>
/// There are no comments for Property Context in the schema.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]
[global::Microsoft.OData.Client.OriginalNameAttribute("Context")]
public virtual string Context
{
get
{
return this._Context;
}
set
{
this.OnContextChanging(value);
this._Context = value;
this.OnContextChanged();
this.OnPropertyChanged("Context");
}
}
@andrewschmidt-a Thank you for reporting the issue. There was a change that was released in the not-so-distant past that introduced a BaseEntityType
class that the proxy classes inherit from. That class contains a property Context
of type DataServiceContext
hence the reason for the conflict. Applying the new
keyword to the property definition would fix the issue but we'd have to determine whether doing that could introduce unforeseen issues before rolling out a fix, i.e.,
public virtual new string Context
{
get
{
return this._Context;
}
set
{
this.OnContextChanging(value);
this._Context = value;
this.OnContextChanged();
this.OnPropertyChanged("Context");
}
}
Adding some information here:
Conflict in property name is part of the issue, it also has some problem when need to refer to DataServiceContext Context value, please check the screenshot.
Using base.Context can be a temp workaround.