Kros.KORM.Extensions.Asp 3.2.0

dotnet add package Kros.KORM.Extensions.Asp --version 3.2.0
                    
NuGet\Install-Package Kros.KORM.Extensions.Asp -Version 3.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kros.KORM.Extensions.Asp" Version="3.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kros.KORM.Extensions.Asp" Version="3.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Kros.KORM.Extensions.Asp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Kros.KORM.Extensions.Asp --version 3.2.0
                    
#r "nuget: Kros.KORM.Extensions.Asp, 3.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Kros.KORM.Extensions.Asp@3.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Kros.KORM.Extensions.Asp&version=3.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Kros.KORM.Extensions.Asp&version=3.2.0
                    
Install as a Cake Tool

Kros.KORM.Extensions.Asp Build Status

For simple integration into ASP.NET Core projects, the Kros.KORM.Extensions.Asp package was created.

Documentation

For configuration, general information and examples see the documentation.

Download

Kros.KORM.Extensions.Asp is available from Nuget Kros.KORM.Extensions.Asp.

Contributing Guide

To contribute with new topics/information or make changes, see contributing for instructions and guidelines.

This topic contains following sections

ASP.NET Core Extensions

You can use the AddKorm extension methods to register databases to the DI container. This registers IDatabaseFactory into DI container. This factory can be used to retrieve IDatabase instances by name. If no name is specified, default name DefaultConnection will be used. IDatabase instances has scoped lifetime.

The first database registered by AddKorm method is also added to the DI container directly as IDatabase dependency. This is for simple use case, when only one database is used. So there is no need for using IDatabaseFactory.

public void ConfigureServices(IServiceCollection services)
{
    services.AddKorm(Configuration);
}

The configuration file (typically appsettings.json) must contain a standard connection strings section (ConnectionStrings). Name of the connection string can be specified as second parameter. If the name is not specified, default name DefaultConnection will be used.

"ConnectionStrings": {
  "DefaultConnection": "Server=ServerName\\InstanceName; Initial Catalog=database; Integrated Security=true",
  "localConnection": "Server=Server2\\Instance; Integrated Security=true;"
}

Connection string can be passed directly to AddKorm method, together with its name. The name DefaultConnection will be used if no name is specified.

public void ConfigureServices(IServiceCollection services)
{
    // Added from appsettings.json under "localConnection" name.
    services.AddKorm(Configuration, "localConnection");

    // Added directly with the name "db2".
    services.AddKorm("Server=ServerName\\InstanceName; Initial Catalog=database; Integrated Security=true", "db2");
}

KORM supports additional settings for connections:

  • AutoMigrate: The value is boolean true/false. If not set (or the value is invalid), the default value is false. If it is true, it allows automatic database migrations.
  • KormProvider: This specifies database provider which will be used. If not set, the value System.Data.SqlClient will be used. KORM currently supports only Microsoft SQL Server, so there is no need to use this parameter.

These settings (if needed) can also be set in configuration file under the KormSettings section. Settings are identified by connection string name.

"KormSettings": {
  "DefaultConnection": {
    "AutoMigrate": true
  },
  "localConnection": {
    "AutoMigrate": true
  }
}

Database Migrations

For simple database migration, you must call:

public void ConfigureServices(IServiceCollection services)
{
    services.AddKorm(Configuration)
        .AddKormMigrations()
        .Migrate();
}

Migrations are disabled by default, so the previous code requires that the automatic migrations are enabled in KormSettings for each connection string: AutoMigrate=true

Korm by default performs migrations by searching the main assembly for files in SqlScripts directory. The script file name must match pattern {migrationId}_{MigrationName}.sql. MigrationId is increasing number over time.

For example: 20190301001_AddPeopleTable.sql

CREATE TABLE [dbo].People (
    [Id] [int] NOT NULL,
    [Name] [nvarchar](255)
CONSTRAINT [PK_People] PRIMARY KEY CLUSTERED ([Id] ASC)
    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

Migration can also be executed through an HTTP request. By calling the /kormmigration endpoint, the necessary migrations will be executed. However, you need to add middleware:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseKormMigrations();
}

You can change the endpoint URL by configuration:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseKormMigrations(options =>
    {
        options.EndpointUrl = "/loremipsum";
    });
}

If multiple KORM databases are registered, all of them have unique name. Migrations are performed per database and the name of the database is specified in URL as another path segment: /kormmigration/dbname If the name is not specified, default connection string will be used (DefaultConnection).

If you have scripts stored in a different way (for example, somewhere on a disk or in another assembly), you can configure your own providers to get these scripts.

public void ConfigureServices(IServiceCollection services)
{
    services.AddKorm(Configuration)
        .AddKormMigrations(o =>
        {
            var assembly = AppDomain.CurrentDomain.GetAssemblies()    .FirstOrDefault(x => x.FullName.StartsWith  ("Demo.DatabaseLayer")  );
            o.AddAssemblyScriptsProvider(assembly,     "Demo.DatabaseLayer.Resources");
            o.AddFileScriptsProvider(@"C:\scripts\");
            o.AddScriptsProvider(new MyCustomScriptsProvider());
        })
        .Migrate();
}

It is possible to set your own timeout for running migration script. Defaul timeout is 30 seconds.

public void ConfigureServices(IServiceCollection services)
{
    services.AddKorm(Configuration)
        .AddKormMigrations(o =>
        {
            o.Timeout = TimeSpan.FromMinutes(1);
        })
        .Migrate();
}

KORM creates a __KormMigrationsHistory table in which it has a history of individual migrations.

Id Generators

If you need to initialize the database for IIdGenerator then you can call InitDatabaseForIdGenerator.

public void ConfigureServices(IServiceCollection services)
{
    services.AddKorm(Configuration)
        .InitDatabaseForIdGenerator();
}

Converters

KORM supports custom converters (via IConverter implementation) for converting values from DB to objects and vice versa. These converters are set for individual columns in OnModelCreating method of database configuration class (DatabaseConfigurationBase).

If you need to convert text formatted as JSON from database to entity, you can use pre-defined converter - JsonConverter:

public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
{
    modelBuilder.Entity<MyEntity>()
        .HasTableName(MyEntityTableName)
        .Property(x => x.MySerializableProperty).UseConverter<JsonConverter>();
}
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Kros.KORM.Extensions.Asp:

Package Downloads
Kros.CqrsTemplate

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.0 133 5/7/2026
3.1.0 213 2/20/2026
3.0.0 350 12/18/2025
2.0.1 653 2/4/2025
2.0.0 283 1/7/2025
1.3.1 16,979 3/25/2022
1.3.0 977 4/21/2021
1.1.0-alpha.7 619 11/3/2020
1.1.0-alpha.6 877 12/13/2019
1.1.0-alpha.5 604 11/26/2019
1.1.0-alpha.4 921 8/2/2019
1.1.0-alpha.3 498 7/28/2019
1.1.0-alpha.2 501 7/25/2019
1.1.0-alfa 727 6/6/2019
1.0.0 982 3/21/2019
0.2.0 1,001 11/3/2018
0.1.0 1,503 11/3/2018