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

Enhancement : Reverse Engineer from an EDMX file? #551

Closed
omatrot opened this issue Oct 31, 2020 · 38 comments
Closed

Enhancement : Reverse Engineer from an EDMX file? #551

omatrot opened this issue Oct 31, 2020 · 38 comments
Labels
enhancement New feature or request reveng

Comments

@omatrot
Copy link
Contributor

omatrot commented Oct 31, 2020

I'm wondering if we could in the future reverse engineer from an existing edmx file ?
Would it be difficult to port the code that existed in the initial EF Power tools ?
I may have some time to dedicate to this task in the near future.

@ErikEJ
Copy link
Owner

ErikEJ commented Oct 31, 2020

I think it could be quite difficult, as the current reverse engineering is based on a database model, not a conceptual edmx model... But interesting thought.

Your task would be to create a class that can create a DatabaseModel from an edmx, have a look at the code that does this from a .dacpac. (that has been serialized into a TSqlModel)

@ErikEJ
Copy link
Owner

ErikEJ commented Oct 31, 2020

Maybe you could use this? https://archive.codeplex.com/?p=linqtoedmx

@omatrot
Copy link
Contributor Author

omatrot commented Nov 1, 2020

All right, let me see what I can do.

@ErikEJ
Copy link
Owner

ErikEJ commented Nov 1, 2020

Perfect, ping me with any design questions.

@ErikEJ
Copy link
Owner

ErikEJ commented Nov 1, 2020

@ErikEJ ErikEJ added enhancement New feature or request reveng labels Nov 10, 2020
@omatrot
Copy link
Contributor Author

omatrot commented Nov 20, 2020

@ErikEJ Just to let you know that I've started the porting process of the old LinqToEdmx to .NET Standard 2.1.

@ErikEJ
Copy link
Owner

ErikEJ commented Nov 20, 2020

Wauw!

@omatrot
Copy link
Contributor Author

omatrot commented Dec 20, 2020

I've published the Linq2Edmx and Linq2xsd nuget packages.
Do you want me to create a branch corresponding to the issue in my forked repo to start the integration process?

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 20, 2020

If you think it adds value, sure, it will mainly be an implementation of DatabaseModelFactory.

i suggest you start with the code generation parts, and verify by running the console app.

@omatrot
Copy link
Contributor Author

omatrot commented Dec 20, 2020

I also have to say that I'm using Visual Studio 2019 for Mac. The EFCorePowerTools project is unrecognised in this environment. I'm open to some alternative build/debug guidelines. Thanks in advance.

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 20, 2020

This is a Visual Studio project, but you could maybe run the code generation parts on Mac...

The end result could be a package similar to the Nuget package for .dacpac support.

But being able to open the solution file is most likely a must, are you able to do that?

If not, we could take a Teams call and I can walk you through the moving parts?

@omatrot
Copy link
Contributor Author

omatrot commented Dec 20, 2020

The solution file opens fine. VS complains that this project is an unknown solution item type.

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 20, 2020

Yes, that is expected for the Vsix project, but you should be able to open the .net Core projects, and they are the important ones...

We are talking in the blind here, is my impression

@omatrot
Copy link
Contributor Author

omatrot commented Dec 20, 2020

All the other projects are loading correctly ;)

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 20, 2020

Ok, then you are good to proceed!

@omatrot
Copy link
Contributor Author

omatrot commented Dec 20, 2020

Yep !

Correct me if I'm wrong but I think I should create two new projects:

  • ErikEJ.EntityFrameworkCore.5.Edmx
  • ErikEJ.EntityFrameworkCore.Edmx

To follow what has been done for Dacpac?

I'll let you validate the namespaces and project names though.

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 20, 2020

Yes, that would be the final outcome.

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 20, 2020

Hmmm... What provider will this target?

The DatabaseModel is provider specific?

@omatrot
Copy link
Contributor Author

omatrot commented Dec 20, 2020

No, it will be provider agnostic.

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 20, 2020

Curious how that will pan out in real life... And runtime it will execute against some database, I presume??

@omatrot
Copy link
Contributor Author

omatrot commented Dec 20, 2020

I think it will depend on what is missing in the Edmx file.

For instance, Index informations are not there, but we may optionally connect to the database to get them. Primary and foreign keys are there of course.

For me the main idea is to never create the database from the scaffolding data, just be able to work with a generated context of an existing database from which one had generated (and tweaked) an edmx in the past.

@ErikEJ
Copy link
Owner

ErikEJ commented Dec 20, 2020

Thanks for the explanation! Makes sense to me...

@omatrot
Copy link
Contributor Author

omatrot commented Jan 18, 2021

Hi @ErikEJ
Quick question just to clarify something: Microsoft.EntityFrameworkCore.Scaffolding.Metadata.DatabaseModel is about the storage part of the relational database? Is there an equivalent for the conceptual part? The EDMX contains both and the mapping between the two.

@ErikEJ
Copy link
Owner

ErikEJ commented Jan 18, 2021

@omatrot
Copy link
Contributor Author

omatrot commented Jan 18, 2021

I would provide both then, if that makes sense to the tooling. That makes sense to me anyway.

@ErikEJ
Copy link
Owner

ErikEJ commented Jan 18, 2021

Tooling does not use the IRelationalModel, but feel free to expose it, we should consider publishing a NuGet package.

@omatrot
Copy link
Contributor Author

omatrot commented Jan 18, 2021

I'm not done yet ;)
If I understand correctly, the tooling expose an IDatatabaseModel that is later processed by EF scaffolding to produce the entities, their configurations and the context?
The EDMX file already contains all that is needed to produce the entities, their configurations and the context.

@ErikEJ
Copy link
Owner

ErikEJ commented Jan 18, 2021

Correct, look at the .dacpac Databasefactory

@omatrot
Copy link
Contributor Author

omatrot commented Feb 8, 2021

Hi @ErikEJ
I think I'm ready to prepare a pull request for this.
Stay tuned.
Thanks for your patience.

@ErikEJ
Copy link
Owner

ErikEJ commented Feb 8, 2021

Wauw - exciting!

@omatrot
Copy link
Contributor Author

omatrot commented Feb 8, 2021

I may have spoken too fast...
I'm confused about what I've done around the IRelationalModel Interface. There seems to be no factory available to create instances of this interface. Could you double check to confirm? And may be provide an alternative?
Thanks in advance.

@ErikEJ
Copy link
Owner

ErikEJ commented Feb 8, 2021

I sincerely doubt there will be many consumers of the IRelationalModel - but do a PR so we can have a fact based discussion?

@omatrot
Copy link
Contributor Author

omatrot commented Feb 8, 2021

PR opened.

@ErikEJ
Copy link
Owner

ErikEJ commented Feb 24, 2021

The PR is now merged, and you can test it by picking an EDMX file via the Select Data Source dialog.

Thanks for your patience!

@ErikEJ ErikEJ closed this as completed Feb 24, 2021
@ErikEJ
Copy link
Owner

ErikEJ commented Feb 25, 2021

Could you describe this selling point of this feature in a sentence? I plan to tweet that it is now available in the latest daily build.

@omatrot
Copy link
Contributor Author

omatrot commented Feb 25, 2021 via email

@ErikEJ
Copy link
Owner

ErikEJ commented Feb 25, 2021

Why don't you try it out?

@omatrot
Copy link
Contributor Author

omatrot commented Feb 26, 2021

I've tried it out ;)
As I was saying, the 'Choose Database Object' step could be avoided completely or displayed as readonly because I can provide you with what the .edmx file contains in the conceptual model, which may specify excluded columns and custom renaming, and is not used so far.

Selling point:
Now you can leverage your existing/maintained .edmx files to scaffold EF Core entities and context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request reveng
Projects
None yet
Development

No branches or pull requests

2 participants