SQL Server
To set up Jerrycurl with a SQL Server database, install the official NuGet package.
dotnet add package Jerrycurl.Vendors.SqlServer
After this, configure your connection with the UseSqlServer
extension.
class MyDomain : IDomain
{
public void Configure(DomainOptions options)
{
options.UseSqlServer("SERVER=.;DATABASE=blogdb");
}
}
If you want to create an initial set of classes, use our CLI with the sqlserver
moniker.
jerry scaffold -v sqlserver -c "SERVER=.;DATABASE=blogdb"
Or, in Visual Studio, simply right-click a .orm
file and pick Jerrycurl -> Generate from Database
.
Features
SQL Server supports both types of output mapping that Jerrycurl can use: output parameters and output data sets.
Procedural elements
OUTPUT
clause
Jerrycurl supports
@model Blog
INSERT INTO @M.TblName()
( @M.In().ColNames() )
OUTPUT @M.Out().Cols("INSERTED").As().Props()
VALUES ( @M.In().Pars() )
Table-valued parameters
Jerrycurl natively supports table-valued parameters as a powerful feature to map an entire relational structure into your database as a single parameter.
To use these, you must first define a structure server-side similar to that of a regular table.
CREATE TYPE dbo.DateRange AS TABLE
(
StartDate datetime2(7) NOT NULL,
EndDate datetime2(7) NOT NULL
)
Create a matching object and map its name with the Table
attribute.
[Table("dbo", "DateRange")]
public class DateRange
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
Supply a List<DateRange>
model, use the special
Tvp
extension to access the table and use Col
to access
columns.
@model DateRange
@result Blog
SELECT @R.Star()
FROM @R.Tbl()
WHERE EXISTS(
SELECT *
FROM @M.Tvp()
WHERE @R.Col(m => m.CreatedOn) BETWEEN @M.Col(m => m.StartDate) AND
@M.Col(m => m.EndDate)
)