SpDtoGen 1.0.0
dotnet tool install --global SpDtoGen --version 1.0.0
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
dotnet tool install --local SpDtoGen --version 1.0.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=SpDtoGen&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package SpDtoGen --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
<div align="center">
🌐 Language / Ngôn ngữ / 言語
🇬🇧 English | 🇻🇳 Tiếng Việt | 🇯🇵 日本語
</div>
sp-dto-gen
A .NET CLI tool that automatically generates C# DTOs from SQL Server Stored Procedures using sp_describe_first_result_set — no SP execution required.
Installation
dotnet tool install -g SpDtoGen
Usage
Generate DTO for a single SP
sp-dto-gen dto \
--connection "Server=localhost;Database=MyDb;Trusted_Connection=true;" \
--sp usp_Order_GetById \
--output ./DTOs \
--namespace MyApp.Application.DTOs
Generate DTOs matching a wildcard pattern
sp-dto-gen dto --connection "..." --sp "usp_Order*" --output ./DTOs
Generate DTOs for all SPs in the database
sp-dto-gen dto --connection "..." --output ./DTOs
Preview without writing files
sp-dto-gen dto --connection "..." --sp usp_Order_GetById --dry-run
Generate record instead of class
sp-dto-gen dto --connection "..." --sp usp_Order_GetById --record
Options
| Option | Alias | Default | Description |
|---|---|---|---|
--connection |
-c |
(required) | SQL Server connection string |
--sp |
-s |
(all SPs) | SP name or wildcard (usp_Order*) |
--output |
-o |
current directory | Output directory for .cs files |
--namespace |
-n |
Application.DTOs |
C# namespace for generated DTOs |
--suffix |
Dto |
Suffix appended to class names | |
--record |
false | Generate record instead of class |
|
--dry-run |
false | Print to console without writing files | |
--force |
-f |
false | Overwrite existing files |
Example output
Given this stored procedure:
CREATE PROCEDURE usp_Order_GetById @Id INT
AS
SELECT
o.OrderId,
o.CustomerName,
o.TotalAmount, -- decimal(18,2)
o.CreatedAt, -- datetime2
o.IsDeleted, -- bit
o.AssignedUserId -- int NULL
FROM Orders o
WHERE o.OrderId = @Id
Generated OrderGetByIdDto.cs:
// <auto-generated>
// Generated by SpDtoGen on 2024-01-15 08:30:00 UTC
// Source SP: [dbo].[usp_Order_GetById]
// </auto-generated>
using System.CodeDom.Compiler;
namespace MyApp.Application.DTOs;
[GeneratedCode("SpDtoGen", "1.0.0")]
/// <summary>DTO for stored procedure [dbo].[usp_Order_GetById]</summary>
public class OrderGetByIdDto
{
public int OrderId { get; set; }
public string CustomerName { get; set; } = string.Empty;
/// <remarks>SQL: decimal(18,2) — precision=18, scale=2</remarks>
public decimal TotalAmount { get; set; }
public DateTime CreatedAt { get; set; }
public bool IsDeleted { get; set; }
public int? AssignedUserId { get; set; }
}
Naming convention
| SP Name | Generated DTO Class |
|---|---|
usp_Order_GetById |
OrderGetByIdDto |
usp_GetAllProducts |
GetAllProductsDto |
sp_Customer_Insert |
CustomerInsertDto |
proc_Report_Monthly |
ReportMonthlyDto |
Known limitations
⚠️ SP using temp tables (
#tempTable) —sp_describe_first_result_setcannot statically analyze SPs that use temp tables. The tool will generate an empty skeleton with a warning comment. You will need to add properties manually.Workaround: Consider rewriting the SP to use table variables (
@tableVar) instead of temp tables — they are fully supported.
- Dynamic SQL (
EXEC(@sql)) cannot be statically analyzed — same behavior as above. - IF/ELSE branches returning different result sets — only the first resolvable branch is used.
- Multiple result sets — only the first result set is generated.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 117 | 4/14/2026 |