-
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
Create valid property identifiers when generating OData client #333
Create valid property identifiers when generating OData client #333
Conversation
280d032
to
108d251
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple - this can't be any worse than the current master.
@microsoft-github-policy-service agree |
When using the ODataConnectedService extension in Visual Studio 2022 to generate C# classes from an unpatched Dynamics 365 10.0.29 OData ($metadata) url, @gregwinterstein 's fix has generated code that compiles correctly. Note: by unpatched I mean that our Dynamics 365 has no hotfix for LCS 753226, nor it can be applied - if you have 10.0.30 or 10.0.31 you can apply it, while 10.0.32+ is supposed to incorporate the fix. |
I'd like to test with non-dynamics sources but am too lazy to compile from source - care to share a build? |
108d251
to
0d3e015
Compare
bfcc9b4
to
8a64678
Compare
Took me a while, but I have just now built @gregwinterstein 's "all-fixes" branch from source and I can confirm it generates a working connected service where the current public version fails miserably. A source feed with dashes in field names no longer lets the compiler stumble over all the invalid subtractions... Sample excerpt /// <summary>
/// There are no comments for Property _SMC_K in the schema.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]
[global::Microsoft.OData.Client.OriginalNameAttribute("_SMC-K")]
public virtual string _SMC_K
{
get
{
return this.__SMC_K;
}
set
{
this.On_SMC_KChanging(value);
this.__SMC_K = value;
this.On_SMC_KChanged();
this.OnPropertyChanged("_SMC-K");
}
}
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]
private string __SMC_K;
partial void On_SMC_KChanging(string value);
partial void On_SMC_KChanged(); 👍 👍 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and found working perfectly
My team really needs these changes. Can we please get them reviewed soon? Please and thank you! @ElizabethOkerio @KenitoInc @habbes @gathogojr |
8a64678
to
6512781
Compare
@gathogojr you had some thoughts around this issue. Could you check this PR? |
@@ -2442,7 +2444,9 @@ internal void WritePropertiesForSingleType(IEnumerable<IEdmProperty> properties) | |||
foreach (IEdmProperty property in properties.Where(i => i.PropertyKind == EdmPropertyKind.Navigation)) | |||
{ | |||
string propertyType; | |||
string propertyName = this.context.EnableNamingAlias ? Customization.CustomizeNaming(property.Name) : property.Name; | |||
string propertyName = IdentifierMappings.ContainsKey(property.Name) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Dictionary<TKey,TValue>.TryGetValue(TKey, TValue)
method instead of ContainsKey
method + Dictionary<TKey,TValue>.Item[TKey]
property. TryGetValue
should be more efficient and cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to TryGetValue()
in a869504
Thank you @gregwinterstein for your contribution. However, it might also not be a breaking change since the proxy classes that are generated in such a scenario do not compile meaning the affected customers are likely to be manually editing the proxy classes to mitigate the issue. |
I confirm: Regenerating is the most frequent use for me. Without this PR, each run requires 1-2 minutes of manual edits afterwards, per feed. This saves time especially then regenerating. |
@gathogojr, it has occurred to me that this pull request may cause some breaking changes because of the way valid identifiers are generated vs the way they were generated previously. I don't have a good solution for that. My main issue is that I am unable to generate proxies that compile for either Dynamics F&O or Dynamics CRM (this doesn't entirely resolve all of the CRM issues due to inconsistent casing in the CRM metadata). This change generates proxies that compile for Dynmaics F&O and gets a lot closer for Dynamics CRM. If backward compatibility is an issue, I'm open to suggestions. |
a869504
to
83cb640
Compare
Co-authored-by: Clément Habinshuti <[email protected]>
Co-authored-by: Clément Habinshuti <[email protected]>
Co-authored-by: Clément Habinshuti <[email protected]>
Co-authored-by: Clément Habinshuti <[email protected]>
Co-authored-by: Clément Habinshuti <[email protected]>
…ild" This reverts commit 27cc60b.
83c6c69
to
590a8f5
Compare
Thank you @gregwinterstein for your contribution |
Edit: This is already available through VS marketplace in 1.1.0:
I just got thrown off because that is not mirrored here on the releases page. |
Modify the code generator to generate valid identifiers
This change resolves the following issues: