2

Can I use the EF Reverse POCO generator directly against a SQL Database Project?

I keep my SQL database definition in a "Visual Studio SQL Database Project", which gives me some nice version control capabilities, schema comparison, and a few nifty deployment features. Sometimes I update the project files from a temporary database during development, but the version-controlled project is always the "truth" for any version.

If I use the EntityFramework Reverse POCO Code First Generator, will I need to round-trip my "truth" through an actual SQL database to generate POCO? Or can I use the POCO generator against a VS Database Project?

I know that the schema of a database project has a sort of meta-presence in various VS database interactions. For example, it shows up with a real database icon in the SQL Server Object Explorer. But I don't know if the code-first generator could/does leverage a similar ability to query it for metadata.

shannon
  • 8,664
  • 5
  • 44
  • 74
  • Currently (VS 2013) this is not possible. BTW this question was asked at the following link, though there aren't any helpful answers yet: http://stackoverflow.com/questions/19392636/generate-entity-framework-model-from-visual-studio-database-project – Keith May 12 '15 at 15:05
  • Thank you Keith. Of course the question you mentioned isn't directly related to the tool I was hoping to use, which gets pretty close to the solution already. I don't think that tool was even mentioned in the thread, unless it's part of the EF Power Tools (and I don't think it is). So I wonder, do you know specifically that the reverse POCO generator doesn't have that ability? – shannon May 12 '15 at 18:36
  • 1
    Correct, it currently does not have that ability. It would be a great feature to have though! – Keith May 12 '15 at 18:55

2 Answers2

1

There is a project called SqlSharpener on GitHub available as a NuGet package.

Description:

Parses SQL files to create a meta-object hierarchy with which you can generate C# code such as stored procedure wrappers or Entity Framework Code-First entities. Generate either manually or by invoking one of the included pre-compiled T4 templates.

Rather than generating code from the database or using a heavy abstraction layer that might miss differences between the database and data access layer until run-time, this project aims to provide a very fast and simple data access layer that is generated at design-time using SQL files as the source-of-truth (such as those found in an SSDT project).

I cannot vouch for it because I have never used it but it seems promising.

Keith
  • 20,636
  • 11
  • 84
  • 125
  • Awesome find, thank you Keith. I will investigate it over the next couple days and reply here. – shannon May 15 '15 at 17:28
  • I should also mention that I get the impression from Rowan Miller after some public discussion that MS is considering adding this feature to VS 2015. – shannon May 15 '15 at 17:32
  • 1
    @shannon, I'm the creator of SqlSharpener. You should definitely be able to do what you are asking using it. I have added a [T4 template](https://github.com/aeslinger0/sqlsharpener/blob/master/examples/SimpleExample/SimpleExample.DataLayer/EFCodeFirstExample.tt) in the [example solution](https://github.com/aeslinger0/sqlsharpener/tree/master/examples/SimpleExample) that you can use to generate your entities. If there is a use-case that isn't covered, feel free to [create an issue](https://github.com/aeslinger0/sqlsharpener/issues) and I'll see if I can account for it. – adam0101 May 26 '15 at 19:07
0

For EntityFramework Reverse POCO Code First Generator, you would need to round-trip through an actual SQL database to generate the code-first code as you cannot use generator against a VS Database Project.

Simon Hughes
  • 3,534
  • 3
  • 24
  • 45