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
701 stars 231 forks source link

Stored procedure input (table) type #493

Open RedRiverWeb opened 5 years ago

RedRiverWeb commented 5 years ago

Hi,

Is there a way to map the input (User-Defined Table) types to classes instead of DataTables?

Here is the test case:

CREATE TYPE dbo.MyType AS TABLE(
    ID int,
    Title nvarchar(20)
)
GO

CREATE PROCEDURE dbo.MyProc
    @UserId int
    , @MyData dbo.MyType readonly
AS
SET NOCOUNT ON;

SELECT 1

Here is the result:

public System.Collections.Generic.List<MyProc_Result> MyProc(
    int? userId, System.Data.DataTable myData)
{
    int procResult;
    return MyProc(userId, myData, out procResult);
}

public System.Collections.Generic.List<MyProc_Result> MyProc(
    int? userId, System.Data.DataTable myData, out int procResult)
{
    var userIdParam = new System.Data.SqlClient.SqlParameter { ParameterName = "@UserId", SqlDbType = System.Data.SqlDbType.Int, Direction = System.Data.ParameterDirection.Input, Value = userId.GetValueOrDefault(), Precision = 10, Scale = 0 };
    if (!userId.HasValue)
        userIdParam.Value = System.DBNull.Value;

    var myDataParam = new System.Data.SqlClient.SqlParameter { ParameterName = "@MyData", SqlDbType = System.Data.SqlDbType.Structured, Direction = System.Data.ParameterDirection.Input, Value = myData, TypeName = "dbo.MyType" };
    if (myDataParam.Value == null)
        myDataParam.Value = System.DBNull.Value;

    var procResultParam = new System.Data.SqlClient.SqlParameter { ParameterName = "@procResult", SqlDbType = System.Data.SqlDbType.Int, Direction = System.Data.ParameterDirection.Output };
    var procResultData = Database.SqlQuery<MyProc_Result>("EXEC @procResult = [dbo].[MyProc] @UserId, @MyData", userIdParam, myDataParam, procResultParam).ToList();

    procResult = (int) procResultParam.Value;
    return procResultData;
}
sjh37 commented 5 years ago

That's a nice idea. EF.Core is first on my list, so once that is out of the way, I can work on adding useful things like this.

R-Norman commented 2 years ago

Looking forward to this feature since I am using table types pretty heavily in a current project using reverse poco. For now, I use extensions for list<> of various types that creates matching typed DataTables for passing to the SPs. Still means syncing the definitions on any change but keeps it in one place.

thomaskirk commented 9 months ago

This enhancement would be very appreciated and useful. I hope to see it someday.