Use Dataverse metadata to improve reverse engineering #2684
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aServiceClient
, this change includes an initial authentication attempt via theServiceClient
from which we can extract the access token. This access token can then be reused for subsequent authentication attempts via both theSqlConnection
andServiceClient
without additional login prompts.