DatabaseLibraryMDS 3.0.12

There is a newer version of this package available.
See the version list below for details.
dotnet add package DatabaseLibraryMDS --version 3.0.12
                    
NuGet\Install-Package DatabaseLibraryMDS -Version 3.0.12
                    
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="DatabaseLibraryMDS" Version="3.0.12" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DatabaseLibraryMDS" Version="3.0.12" />
                    
Directory.Packages.props
<PackageReference Include="DatabaseLibraryMDS" />
                    
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 DatabaseLibraryMDS --version 3.0.12
                    
#r "nuget: DatabaseLibraryMDS, 3.0.12"
                    
#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 DatabaseLibraryMDS@3.0.12
                    
#: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=DatabaseLibraryMDS&version=3.0.12
                    
Install as a Cake Addin
#tool nuget:?package=DatabaseLibraryMDS&version=3.0.12
                    
Install as a Cake Tool

DatabaseLibraryMDS

About

The DatabaseLibraryMDS is a library for accessing Sql Server databases using the Microsoft.Data.SqlClient.

Built with .NET 8 the DatabaseLibraryMDS library is for performing CRUD operations on a SQL Server database with minimal code for the developer.


Key Features

  • Makes reading and writing data to and from a database easier with less coding
  • Automatically maps columns to properties when retrieving data
  • Converts returning values according to the data type of the property
  • Supports setting the query timeout
  • Supports Async calls
  • Supports Transactions
  • Supports logging errors to the Windows Event Log
  • Supports Unit Testing

How to Use

   Executes a query that returns a List<Email>
   public List<Email> Email(string connectionString, string parameter)
   {
       try
       {
           using (var ss = new SqlServer(connectionString, CommandType.StoredProcedure))
           {
               string queryString = "Runbook.dbo.cspGetEmailByEmailId";
               ss.AddParameter("@parameter", parameter);
               return ss.ExecuteReader<Email>(queryString);
           } 
       }
       catch (Exception e)
       {
           throw new Exception(e.Message, e);
       }
   }
   
   Executes an Insert statement that returns a Guid for the record ID
       NOTE: The stored procedure will need to OUTPUT the new ID
   public Guid Email(string connectionString, Email Email)
   {
       try
       {
           using (var ss = new SqlServer(connectionString, CommandType.StoredProcedure))
           {
               string spName = "Runbook.dbo.cspAddEmail";
               return ss.ExecuteForGuid(spName, Email);
           } 
       }
       catch (Exception e)
       {
           throw new Exception(e.Message, e);
       }
   }

BulkInserts

// Example — synchronous DataTable bulk insert (with transaction)
using System;
using System.Data;
using DatabaseLibraryMDS;

var dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("CreatedAt", typeof(DateTime));

dt.Rows.Add(1, "Alice", DateTime.UtcNow);
dt.Rows.Add(2, "Bob", DateTime.UtcNow);

string connectionString = "Server=.;Database=MyDb;Trusted_Connection=True;";

using var sql = new SqlServer(connectionString, System.Data.CommandType.Text, Timeout: 60, useEventLogs: false);
try
{
   sql.BeginTrans(); // optional — BulkInsert will enlist in DbCommand.Transaction when present
   int attempted = sql.BulkInsert(dt, "dbo.MyTargetTable", batchSize: 500);
   sql.CommitTrans();

   Console.WriteLine($"Rows attempted: {attempted}");
}
catch (Exception ex)
{
   try { sql.RollbackTrans(); } catch { }
   Console.WriteLine($"BulkInsert failed: {ex.Message}");
}

// Example — async POCO list bulk insert (requires ToDataTable() extension used in this project)
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DatabaseLibraryMDS;

public record Person(int Id, string Name, DateTime CreatedAt);

async Task ExampleAsync()
{
   var items = new List<Person>
   {
       new Person(1, "Alice", DateTime.UtcNow),
       new Person(2, "Bob", DateTime.UtcNow)
   };

   string connectionString = "Server=.;Database=MyDb;Trusted_Connection=True;";
   await using var sql = new SqlServer(connectionString, System.Data.CommandType.Text, Timeout: 60);

   try
   {
       int attempted = await sql.BulkInsertAsync(items, "dbo.MyTargetTable", batchSize: 1000);
       Console.WriteLine($"Rows attempted: {attempted}");
   }
   catch (Exception ex)
   {
       Console.WriteLine($"BulkInsertAsync failed: {ex.Message}");
       throw;
   }
}

await ExampleAsync();

LoneWorx.com

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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 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 DatabaseLibraryMDS:

Package Downloads
BlazorChat.Server.SqlServer

SQL Server persistence provider for BlazorChat.Server. Production-ready database storage implementation. Auto-installs BlazorChat.Server dependency. Requires SQL Server 2016+ or Azure SQL Database.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.14 35 3/13/2026
3.0.13 104 3/7/2026
3.0.12 360 12/19/2025
3.0.11 278 11/7/2025
3.0.10 213 11/5/2025
3.0.9 1,488 7/21/2025
3.0.8.1 143 7/18/2025
3.0.8 142 7/18/2025
3.0.7 290 6/25/2025
3.0.6 588 5/18/2025
3.0.5 199 5/17/2025
3.0.4 285 5/16/2025
3.0.3 291 5/15/2025
3.0.2 296 5/15/2025
3.0.1 49,983 5/15/2025

3.0.12 - Updated library for .net9.0 and .net10.0