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

Use Dataverse metadata to improve reverse engineering #2684

Merged
merged 6 commits into from
Dec 7, 2024

Conversation

MarkMpn
Copy link
Contributor

@MarkMpn MarkMpn commented Dec 2, 2024

When reverse engineering via the Dataverse TDS Endpoint, retrieve the metadata via the Dataverse SDK.

Primary & foreign keys

All tables in Dataverse have a single guid primary key at the application layer, but some system tables are implemented with a compound primary key at the SQL layer which is exposed through the TDS Endpoint. This prevents the guid foreign keys in other tables being used as navigation properties.

By taking the primary key definition from the metadata instead of the SQL system views we get a more consistent view of the primary & foreign key constraints that can be reliably used to build the navigation properties as well as feeling more familiar to a Dataverse developer.

Fixes #2535

Table & column naming

Tables and columns are exposed using their lowercase logical names in the TDS Endpoint. This leads to some hard-to-read code when we get property names like Address1stateorprovince.

By overwriting the names with the schema names from the metadata we get additional capitalisation so the property names tend to end up in PascalCase, e.g. Address1StateOrProvince.

The translation from logical to schema names is only done where there is only a difference in the casing, so the generated SQL will still be valid.

Authentication

The TDS Endpoint and SDK use the same tokens for authentication. To avoid additional login prompts during the reverse engineering process when we switch from using a SqlConnection to a ServiceClient, this change includes an initial authentication attempt via the ServiceClient from which we can extract the access token. This access token can then be reused for subsequent authentication attempts via both the SqlConnection and ServiceClient without additional login prompts.

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 2, 2024

@MarkMpn Great! I wonder if it would be possible to move the Xrm dependent code to a seperate class for even lower impact?

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 3, 2024

@MarkMpn You need to bump the file count check due to the added dependencies: https://github.com/ErikEJ/EFCorePowerTools/actions/runs/12115446223/job/33809089498?pr=2684 (Bump to 166 for EF Core 8)

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 7, 2024

@MarkMpn Any plans to follow up on this?

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 7, 2024

Amazing! I plan a new release to marketplace this weekend.

@ErikEJ ErikEJ merged commit cbd79d3 into ErikEJ:master Dec 7, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance Dataverse reverse engineering
2 participants