EFCorePowerTools icon indicating copy to clipboard operation
EFCorePowerTools copied to clipboard

[Feature] Support Stored Procedures and Functions for other providers

Open pgkdev opened this issue 4 years ago • 26 comments

Tested EF Core Power Tools to reverse engineer an Oracle Database, I was able to create models for tables and views but not for Stored Procedures included in Oracle Packages.

Steps to reproduce

Create Oracle Database with a Package and a Stored procedure. Using EF Core Power Tools, try to reverse engineer to create model for Stored Procedure inputs and outputs. (Maybe it only supports SQL Server SPs for now, like shown in project pages, but Oracle support for SPs will be implemented soon? Need it, thanks :)

Further technical details

EF Core Power Tools version: 5.2.406

Database engine: Oracle XE 184 Win64

Visual Studio version: (e.g. Visual Studio 2019 16.8.3)

pgkdev avatar Jan 04 '21 16:01 pgkdev

Not something I plan to implement, as I no nothing about Oracle, and had no test server.

But a PR would be welcome, if you want to do that, I can provide more implementation details.

Code for Postgres stored proc discovery:

https://github.com/vb-consulting/NpgsqlRest/blob/master/NpgsqlRest/RoutineSourceQuery.cs

ErikEJ avatar Jan 04 '21 16:01 ErikEJ

Unfortunately I don't have the time and the knowledge to implement a complicated piece of software like this.

I was liking so much this tool, it seem perfect but then notice this missing feature for Oracle, and I have lots of SPs :s Do you have some alternative solution for this?

Thanks and great project "EF Core Power Tools".

pgkdev avatar Jan 04 '21 17:01 pgkdev

It is actually not that complicated. But maybe someone else can step up @ProH4Ck ?

ErikEJ avatar Jan 04 '21 17:01 ErikEJ

Ok... I'll check in the next few days if this is possible but I remember that something is not yet implemented in Oracle EF Core provider (UDTs for example)... I need to check if basic stored procedures work and if they'll work, I'll add support to EF Core Power Tools.

ProH4Ck avatar Jan 04 '21 20:01 ProH4Ck

Fantastic! Feel free to ask me for implementation suggestions/advice.

ErikEJ avatar Jan 04 '21 20:01 ErikEJ

In Oracle, it is common to group stored procedures and functions in packages. In the project that I had to deal with Oracle, I had a separate static class for each Oracle package that contained an extension method on DbContext for every sproc/function found in that package.

I can help with adding support for Oracle too.

Giorgi avatar Jan 14 '21 14:01 Giorgi

I would prefer an implementation that resembles the SQL Server implementation as closely as possible

ErikEJ avatar Jan 14 '21 15:01 ErikEJ

How do you deal with sprocs that have the same name but have different schema?

Giorgi avatar Jan 14 '21 15:01 Giorgi

Specify the schema name when calling them...

But I think schema may mean something completely different in Oracle

ErikEJ avatar Jan 14 '21 15:01 ErikEJ

Yes, the schema is a different thing in Oracle. In Oracle, you can have sprocs with the same name but in different packages. Specifying the package name every time you call a sproc means having to type it manually, but we can have it generated by grouping the sprocs in separate classes instead of having one giant class holding all sprocs/functions.

Giorgi avatar Jan 14 '21 15:01 Giorgi

Ah, I think I get your question now. I name the method SchemaMethodName if there are duplicates.

Have a look at the current implementation.

ErikEJ avatar Jan 14 '21 15:01 ErikEJ

I see. Well, I would prefer to have

var procedures = new NorthwindContextProcedures(db);
procedures.SchemaName.SprocName(param1, "param2");

But I guess it's too late to change? It would align with how you execute them in the database and would help clean up intellisense too.

Also, what do you think about returning a named tuple when the sproc has multiple output parameters instead of using OutputParameter?

Giorgi avatar Jan 14 '21 15:01 Giorgi

It is actually SprocnameSchemaname.

Tuples would be a breaking change as well, and changing the API is also not what this feature is about.

ErikEJ avatar Jan 14 '21 20:01 ErikEJ

In Oracle, it is common to group stored procedures and functions in packages. In the project that I had to deal with Oracle, I had a separate static class for each Oracle package that contained an extension method on DbContext for every sproc/function found in that package.

I can help with adding support for Oracle too.

I can confirm this, we have Procedures and Functions in packages.

pgkdev avatar Jan 15 '21 10:01 pgkdev

@pgkdev why was this closed?

ErikEJ avatar Jan 15 '21 11:01 ErikEJ

I think you must try to implement something, or explain with examples, my Oracle knowledge is zero.

ErikEJ avatar Jan 16 '21 12:01 ErikEJ

@pgkdev why was this closed?

It was a click mistake, sorry :s

pgkdev avatar Jan 18 '21 11:01 pgkdev

I think you must try to implement something, or explain with examples, my Oracle knowledge is zero.

It's +- like me, I'm using what other IT team provided for Oracle DB schema. But noticed that, stored procedures inside packages.

pgkdev avatar Jan 18 '21 11:01 pgkdev

@ProH4Ck any news on the implementation? Need that :)

pgkdev avatar Jan 27 '21 12:01 pgkdev

Is someone working on this issue? I need this for my projekt now otherway i need to use a other framework/tool

kevinvenclovas avatar Sep 01 '21 18:09 kevinvenclovas

No, this issue needs help from experts in the various RDBMS systems.

ErikEJ avatar Sep 01 '21 18:09 ErikEJ

Oke thanks. Is there a workaround? Is there a option to execute a raw sql string to execute my procedur?

kevinvenclovas avatar Sep 01 '21 18:09 kevinvenclovas

Sure, you can just hand code what the stored procedure mapping does (run against a SQL Server db, or see the code in the GitHub repo ( in the ScaffoldingTester project)

ErikEJ avatar Sep 01 '21 18:09 ErikEJ

Closing and moving to Backlog milestone

ErikEJ avatar Nov 22 '21 13:11 ErikEJ

@ErikEJ you mentioned not implementing because of no knowledge of Oracle, is this the same for MySQL? My team is trying to reverse engineer the stored procedures in our MySQL Database, but it seems this doesn't support that yet.

andrewdci03 avatar Apr 13 '23 19:04 andrewdci03

@andrewdci03 Correct, only SQL Server / Azure SQL stored procedures are supported, but I am willing to help anyone with a PR

ErikEJ avatar Apr 14 '23 06:04 ErikEJ

I am going to close this general issue, and wait for community PRs now that I have implemented Postgres stored function / stored procedure support (and laid the groundwork for others)

ErikEJ avatar Jun 15 '24 12:06 ErikEJ