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

Dataverse reverse engineering - foreign keys #34686

Open
MarkMpn opened this issue Sep 16, 2024 · 2 comments
Open

Dataverse reverse engineering - foreign keys #34686

MarkMpn opened this issue Sep 16, 2024 · 2 comments

Comments

@MarkMpn
Copy link

MarkMpn commented Sep 16, 2024

When I reverse engineer tables from Microsoft Dataverse, all primary keys and therefore foreign keys are ignored and so I cannot use properties to access related records in the way I am used to with standard SQL Server databases.

I have a change that I would like to submit to extend the index and foreign key handling in the SQL Server reverse engineering logic to allow it to work with Dataverse - is this something you would be interested in?

To join two tables in Dataverse today requires code like:

var results = ctx.Accounts
  .Join(ctx.Contacts, a => a.Primarycontactid, c => c.Contactid, (a, c) => new { a, c })
  .Select(ac => new { ac.a.Name, ac.c.Fullname });

It would be much nicer to be able to use lookup properties like:

var results = ctx.Accounts
  .Select(a => new { a.Name, a.Primarycontact.Fullname });

This currently isn't possible because the indexes are ignored during reverse engineering, so the foreign keys can't be used because it doesn't recognise the corresponding primary key. dotnet ef dbcontext scaffold produces warnings like:

Could not scaffold the foreign key 'dbo.account(primarycontactid)'. A key for 'contactid' was not found in the principal entity type 'Contact'.

EF Core version: 8.0.8
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 9.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.10

@ErikEJ
Copy link
Contributor

ErikEJ commented Sep 16, 2024

That would be interesting to see a PR for - feel free to reach out, I created the original PR to enable Dataverse support.

@MarkMpn
Copy link
Author

MarkMpn commented Sep 16, 2024

Thanks, I've submitted it as #34689

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants