-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Reverse engineer/scaffold stored procedures #15105
Comments
@WalterW Which tooling are you referring to, specifically? |
Specially the Model Browser which available for EF6x. The goal is have a easy method to map and generate a c# method for SP. One of the stopping block for us to start a project in .Net Core is because of this due to productivity. Spoke to @divega on this matter earlier of the week in campus. |
My understanding (@WalterW correct me if I am wrong), is that you would like to see EF Core's DbContext scaffolding becoming capable of generating methods for each stored procedure in the database that return entity results. |
Scaffolding to generate method just one part of it, another part is to have a tool such as Model Browser to refresh the custom entity object (complex types) every time SP change the return values. |
Triage:
|
"Visual tool such as the Model Browser - this is something we have no plans to implement." @ajcvickers interesting.... any specific reason on this? |
@WalterW We have found visual tools (especially those in Visual Studio) are very expensive to both build and maintain. So, even with a bigger team, I'm not sure the ROI would be worth it, but with the current team size there is no way we can take on anything like this. |
@ajcvickers understand. Thanks for the information. |
pretty please add this! |
We are eagerly waiting for the support of scaffolding stored procedures with EFCore to migrate parts of our application from EF6 to EFCore. For our project, there is no need for a visual tool, a simple whitelist like the current “-tables” parameter should be enough. What we cannot discern of the conversations in this and other issues is how far the work for the support of Views and Stored Procedures has progressed and how likely it is that parts of this get implemented for 3.0. |
@Lupin1st How would you expect a reverse engineer of stored procs to work - can you supply a code sample or the proc and the corresponding generated code? |
Perhaps as it does in EF6?
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Erik Ejlskov Jensen <notifications@github.com>
Sent: Thursday, May 9, 2019 12:27 PM
To: aspnet/EntityFrameworkCore
Cc: Joel Roberts; Comment
Subject: Re: [aspnet/EntityFrameworkCore] Reverse engineer/scaffold stored procedures (#15105)
@Lupin1st<https://github.com/Lupin1st> How would you expect a reverse engineer of stored procs to work - can you supply a code sample or the proc and the corresponding generated code?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#15105 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ACMKFFAIDYL52VTAVJJAAMTPURNHPANCNFSM4HAHP2NQ>.
|
EF6 is being ported to .net core. It can be an option for some scenarios. |
I have created a small project with a simple use case for a procedure mapping sample that fits our needs. Functions could be generated in a similar way but should return an IQueryable object. We currently use EF6 and will surely port to EF6 on .Net Core 3.0 when its available. But we still want to migrate new modules to EFCore as well. Concerning the way procedures should get generated from EFCore scaffold. For us the procedures and functions generated from the Entity framework 6 work well enough but using EFCore could probably make a meaningful difference for our project. Our application uses many hundred tables and Views and even more procedures and functions. Most of our legacy code uses only procedures to access data. For newer Modules however, we decided to use procedures only for performance reasons and query with EF6 queries. We want both, queries and procedure/function calls to get replaced by EF Core equivalents, at least for new modules. We do not make changes to the generated EF6 Models, so we use the designer only for selecting which objects should get imported. The reasons we do not want to stick with EF6 are as following (ordered by priority):
For generating the procedures and functions, it would be enough for us to use the following SQL-Server objects. [sys].[dm_exec_describe_first_result_set_for_object]: INFORMATION_SCHEMA.ROUTINES and INFORMATION_SCHEMA.PARAMETERS: |
We also use EF6 and rely on the support of stored-procedures. Stored-procedures provide a level of control that generated SQL cannot provide. (This is not a limitation of ef-core; it's merely the nature of the beast. Some times, you actually need to manhandle the SQL.) And we also have hundreds of tables. Concerning the problems mentioned by @Lupin1st:
Our homegrown tool (written in C#) pulls the model from the database and generates POCO objects which (when serialized as XML) generate the EDMX. To be clear, we have a collection of simple objects to represent the database (Schema, Table, Column, StoredProcedure, etc.); and we have a collection of simple objects to represent the EDMX (EntitySet, Entity, Property, ImportFunction, etc.). Secondarily, the tool provides a simple mechanism to pass the model into T4 templates (which can be specified by config-file or on a command-line). Then, each T4 template can generate whatever it wants using the information from the model. (We have a series of templates which enforce our database-conventions. For example, one template will rename any foreign-key which doesn't match our convention. Another template will ensure audit-columns (ChangeDate, CreateDate, etc.) are added to each table. Another template generates CUD stored-procedures.) Plus, as I mentioned earlier, the T4 templates which are dependent on the EDMX have also been customized. Our customizations enable us to use SQL extended-properties for customized purposes as well as things like passing user-defined table-types into stored procedures. Also, our customizations generate resource-files for each entity (easing the support of whole-platform localization). These resource-files are resistant to code-regeneration (if a resource-entry for the FirstName column already exists, don't overwrite it). Overall, I feel like we've taken ownership of the EF6 experience. And yet, the EDMX still feels overly weighty. Conceivably, we could use our tool to generate ef-core "code-first" code; but the lack of stored-procedure support is a major loss. |
Thanks for the detailed info @harley333 and @Lupin1st. This will be useful when we get to this in EF Core. |
Any updates on scaffolding StoredProcedure in EF Core? |
@anomepani This issue is in the Backlog milestone. This means that it is not planned for the next release (EF Core 5.0). We will re-assess the backlog following the this release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources. |
The "partial" support for the stored procedures is the reason why my company is still not migrating to aspnetcore the existing projects and the new starting projects... |
Guys, have a look there: https://github.com/DarioN1/SPToCore I have created a kind of scaffolder for Stored Procedure, I'm using it in a new project that uses an existing database with more than 300 stored procedures. At the moment it works very well... Let me know your opinion ! |
We are eagerly waiting for this! 1000+ stored procs / functions make it a tough move to switch to EFCore. This is the biggest missing feature vs EF6 for us. |
@jyeagle it is possible today with EF Core Power Tools... |
@ErikEJ I saw this, but unfortunately we are not using EF Core 3.1 yet....trying to find a 2.1 solution. |
@ErikEJ When I try to Reverse Engineer a Stored Procedure (witch runs other SPs inside) with EF Power Tools (latest version), it fails and then the Output also fails, so I cant get to se why. Any guess? |
Noting in the VS output window? Have a look at the docs and the source code, most likely calling sp_describe_first_resultset fails or sys.parameters returns an unexpected value. |
@ErikEJ Yeah, there was a second error "Unable to log error to Output Window". Thanks a lot! sp_describe_first_result_set helped in finding the problem! There was a Temp Table in one of the internal SPs that caused the problem. |
Docs on this feature in EF Core Power Tools https://github.com/ErikEJ/EFCorePowerTools/wiki/Reverse-Engineering#sql-server-stored-procedures |
I am eagerly waiting for this as well so I can migrate some of the least performant code dealing with my db in my C# on over to an SP. |
@AraHaan this is just about scaffolding stored procedures, and should not be blocking from using them. Stored procedures can already be managed in migrations via raw SQL. |
while that is true, it does not go around to generate the code to call it on the .NET side (I think). |
@AraHaan EF Core Power Tools can do that for you today (as already mentioned above) |
@ErikEJ does efcore power tools have cli command to generate along with ef scaffolding |
as much as I like the efcore power tools, I would rather use stuff that is built into the actual scaffolder more and feel it would be better that way if the power tools functionality was actually 1:1 with the scaffolder so that way the power tools become optional, but you still get the same exact functionality in the default scaffolder as well. |
Ah I see. Thanks It would be great if the underlying packages are published on nugget. |
In a somewhat extreme case, I'm looking at data access options for a project where the db is siloed behind sprocs (so more like generating a web service client than a traditional ORM). Is this a use case that ef core might eventually support (no linq, change tracking, migrations, or even a domain model)? |
@yori-s EF Core Power Tools stored procedure mapping should be able to do that for you... |
Oh please, I'd really appreciate this! Maybe there is some hoop jumping procedure to make normal Visual Studio run on Linux so I can use Erik's but it would be mighty convenient to this feature in |
@subchannel13 EF Core Power Tools CLI is cross platform and supports stored procedures |
Btw I made a source generator that takes EDMX and writes the code side of it for EG6 AND EFCore, the EdmxSourceGenerator. |
https://github.com/Elskom/EdmxSourceGenerator/tree/main https://github.com/Elskom/EdmxSourceGenerator/blob/main/Internal/FunctionImport.cs Simple I recommend creating dummy .NET Framework project to create and edit the edmx file, then using this source generator with that file set to With this, this issue is technically implemented. Good thing I took the time back when I needed edmx and the edmx code generator built into VS back then was broken 2 years ago now in my Fall Semester where I needed it for my capstone class. So I sat down 1 week and reverse engineered it from scratch by looking at the file's contents and figuring it out and then logged my progress so I got graded on manually fixing this issue with a source generator workaround. |
The tooling of SP mapping with EF 6x is great. Please migrate it over to EF code so it can be easier for developer.
The text was updated successfully, but these errors were encountered: