sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
706 stars 229 forks source link

Support targeting an SSDT project for reverse-engineering #496

Open daiplusplus opened 5 years ago

daiplusplus commented 5 years ago

Previously I used to design my databases using a live SQL Server instance running on my LAN server using SSMS and import them into SSDT using Schema Compare, but lately I now do most of my original design work in SSDT and then Publish to my LAN server and then run EF database reverse-engineering against that server - this isn't exactly ideal because doing a publish-then-compare is time-consuming for complex databases, and it doesn't help that VS still blocks the UI when T4 scripts run.

I'm currently working on projects that really don't need a development SQL Server instance - but I still need it to run the EF database reverse-engineering tools against (including this T4 script).

SSDT does actually run a LocalDb instance with this default connection string:

Data Source=(localdb)\ProjectsV13;Initial Catalog={projectName};Integrated Security=True;Pooling=False;Connect Timeout=30

However SSDT doesn't actually replicate the project database design in this database until/unless you start an SSDT debugging session using default settings or explicitly publish the project to it.

I'm curious if there's any other way for a T4 script to access the object-model of an SSDT project to discover the database structure. Has anyone ever poked-around the managed-code components of SSDT (e.g. Schema Compare) when it compares an SSDT project to a live database and saw how it works?

ErikEJ commented 5 years ago

I enumerate a SSDT dacpac model in EF Core Power Tools (Reverse engineering from a SSDT dacpac) - sample code: https://github.com/ErikEJ/EFCorePowerTools/blob/master/src/GUI/ReverseEngineer20/ReverseEngineer/SqlServerDacpacDatabaseModelFactory.cs