Iota 1.1.0
See the version list below for details.
dotnet add package Iota --version 1.1.0
NuGet\Install-Package Iota -Version 1.1.0
<PackageReference Include="Iota" Version="1.1.0" />
paket add Iota --version 1.1.0
#r "nuget: Iota, 1.1.0"
// Install Iota as a Cake Addin
#addin nuget:?package=Iota&version=1.1.0
// Install Iota as a Cake Tool
#tool nuget:?package=Iota&version=1.1.0
Overview
Iota is a C# code generator that creates classes and methods from SQL Server stored procedures or queries.
Features and benefits
- Generate classes based on columns selected by a procedure
- Generate classes based on parameters used by a procedure
- Generate static instances for tables with rows that rarely change (i.e.
CustomerStatus
) - Generate methods that call procedures
- Generate synchronous or asynchronous methods
- Handle common input or output parameters (i.e.
@ID_CURRENT_USER
,@MODIFIED_ON
,@ERROR_MESSAGE
etc.) - Generated code works on .Net Framework and .Net Core
- Very fast
Usage
Use it in three simple steps:
- Create an instance of
Iota.SqlServer.CSharp.ProgramGenerator
- Add the stored procedures and what code you want to generate from them
- Write the generated code
Examples
Create the program generator
using Iota.Metadata;
using Iota.SqlServer.CSharp;
...
ProgramGenerator generator = new ProgramGenerator(sqlServerConnectionString)
{
DefaultNamespace = "MyProject.Entities", // Set namespace for generated classes
DefaultAsyncMode = AsyncMode.Asynchronous, // Choose from synchronous or synchronous methods
DefaultTimeout = 120, // Set default timeout (in seconds) for SQL commands
AdapterNamespace = "MyProject.Services", // Set namespace for generated adapter
AdapterName = "DataAdapter" // Set class name for generated adapter
};
Create types from stored procedures
Generate class Customer
from columns selected by the procedure and class CustomerFilter
from procedure's parameters:
generator
.WithProcedure("dbo", "usp_Customers_Select")
.AddType("Customer")
.AddTypeFromParameters("CustomerFilter");
Handle common parameters
When most of the procedures have the same parameter (i.e. a parameter called @ID_CURRENT_USER
that holds the logged in user id) use this syntax to automatically handle the parameter(s) for all procedure calls:
generator.AddDefaultParameterService(
new ParameterService
{
ParameterNames = new string[] { "IdCurrentUser" },
Initializer = true, // Initialize the parameter before calling the procedure
HideParameters = true // Hide the parameter when generating classes and methods
});
After this, you can write a method to initialize the current user for all commands:
namespace MyProject.Services
{
partial class DataAdapter
{
void InitializeIdCurrentUser(ref int? idCurrentUser)
{
// TODO: Add your logic here
}
}
}
Map table types
Create a class for a table type and map all appearances of the table type to the new class:
generator.MapTableType("dbo", "TblTypCustomers", "TblCustomer");
Create list methods
Generate method CustomersSelect
that receives a CustomerFilter
, calls the stored procedure and returns a list of Customer
instances:
generator
.WithProcedure("dbo", "usp_Customers_Select")
.AddList("Customer", "CustomersSelect", "CustomerFilter");
Create single object methods
Generate method CustomersGet
that calls the stored procedure and returns a single Customer
instance:
generator
.WithProcedure("dbo", "usp_Customers_Get")
.AddFirstObject("Customer", "CustomersGet");
Create non query methods
Generate method CustomersSave
that receives a Customer
and then calls the stored procedure passing all properties as parameters:
generator
.WithProcedure("dbo", "usp_Customers_Save")
.AddNonQuery("CustomersSave", "Customer");
Generate method CustomersDelete
that calls the stored procedure:
generator
.WithProcedure("dbo", "usp_Customers_Delete")
.AddNonQuery("CustomersDelete");
Create scalar methods
Generate method CustomersGetRevenue
that calls the stored procedure and returns a single decimal value:
generator
.WithProcedure("dbo", "usp_Customers_GetRevenue")
.AddScalar("System.Decimal", "CustomersGetRevenue");
Generate method CustomerSelectContactNames
that calls the stored procedure and returns a list of string values:
generator
.WithProcedure("dbo", "usp_Customers_SelectContactNames")
.AddScalarList("System.String", "CustomerSelectContactNames");
Create static instances
Generate static instances of type CustomerStatus
from rows returned by a stored procedure, and place them in an array named Instances
generator
.WithProcedure("dbo", "usp_CustomerStatus_Select")
.AddType("CustomerStatus")
.AddInstances("CustomerStatus", "Name", "Instances");
Create constants
Generate constant fields in type CustomerStatus
from rows returned by a stored procedure. Each constant will have the same name as the status and the same value equal to the status id.
generator
.WithProcedure("dbo", "usp_CustomerStatus_Select")
.AddInstances("CustomerStatus", "Name", "IdStatus");
Write the generated code
Use this sample to write all generated code to a single file:
generator.WriteAll("Generated.cs");
Customization
- Use the
Write
method overrides to write the generated code to multiple files. - Use the optional parameters for the
Add
methods to customize individual stored procedure calls.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.11 | 165 | 5/31/2023 |
1.1.10 | 127 | 5/31/2023 |
1.1.9 | 119 | 5/31/2023 |
1.1.8 | 254 | 1/13/2023 |
1.1.7 | 433 | 2/6/2022 |
1.1.6 | 396 | 2/5/2022 |
1.1.5 | 363 | 12/10/2021 |
1.1.4 | 352 | 11/3/2021 |
1.1.3 | 397 | 11/21/2020 |
1.1.2 | 468 | 4/30/2020 |
1.1.1 | 437 | 4/24/2020 |
1.1.0 | 436 | 4/21/2020 |
1.0.4 | 605 | 9/28/2019 |
1.0.3 | 504 | 9/25/2019 |
1.0.2 | 546 | 9/23/2019 |
1.0.1 | 515 | 9/22/2019 |
Can generate constant fields.
Can use table types as parameters.
Can clear the memory cache used during generation.
Simplified CommandText for stored procedures.
Fixed error produced by query expressions with no alias.
Fixed type mapping for time and timestamp (breaking).
Use PascalCase for properties generated by AddInstances (breaking).