EF Reverse POCO against a SQL Database Project?

断了今生、忘了曾经 提交于 2019-12-20 03:31:12

问题


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.


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/30179726/ef-reverse-poco-against-a-sql-database-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!