Xyapper.MsSql 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Xyapper.MsSql --version 1.0.3
NuGet\Install-Package Xyapper.MsSql -Version 1.0.3
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="Xyapper.MsSql" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xyapper.MsSql --version 1.0.3
#r "nuget: Xyapper.MsSql, 1.0.3"
#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.
// Install Xyapper.MsSql as a Cake Addin
#addin nuget:?package=Xyapper.MsSql&version=1.0.3

// Install Xyapper.MsSql as a Cake Tool
#tool nuget:?package=Xyapper.MsSql&version=1.0.3

Xyapper

A lightweight ORM wrapper for ADO.NET providers

NuGet Version and Downloads count alternate text is missing from this package README image

Advantages

All-purpose. Works great with any ADO.NET provider!

Tiny and lighweight. Has only one external dependency for logging.

Blazing fast. It uses and runtime compile expressions to deserialize data faster than competitors!

Supports logging out of the box.

Flexibility. Developer can specify mappings and even write own deserializers.

Legacy friendly. Yes, DataTables are also supported.

Usage examples

Create a connection singleton factory (here is MS SQL connection)

public static SqlConnection Connection
{
	get
	{
		return new SqlConnection("Data Source=localhost;Database=mydatabase;User Id=sa;Password=mypassword");
	}
}

Set up logging (here we use NLog, but any logging provider with Microsoft.Extensions.Logging.ILogger interface will suit)

XyapperManager.EnableLogging = true;
XyapperManager.Logger = new NLog.Extensions.Logging.NLogLoggerFactory().CreateLogger("Xyapper");
XyapperManager.CommandLogLevel = LogLevel.Trace;
XyapperManager.ExceptionLogLevel = LogLevel.Error;

Select a single value from database

int? result = Connection.XQueryScalar<int?>("SELECT @value", new {Value = 1});

Select a collection of objects

var data = Connection.XQuery<MyCustomType>("SELECT * FROM [dbo].[MyCustomTypeTable]");

Or just a first record

var data = Connection.XQuerySingle<MyCustomType>("SELECT * FROM [dbo].[MyCustomTypeTable]");

Declare types to be deserialized automatically

public class MyClass
{
	public int FieldInt { get; set; }

	public string FieldString { get; set; }

	public DateTime FieldDateTime { get; set; }

	[ColumnMapping(ignore:true)]
	public float FieldToIgnore { get; set; }

	[ColumnMapping(columnName: "FieldInt")]
	public int FieldToMap { get; set; }
}

and query them easyly

var myResult = Connection.XQuery<MyClass>(
	"SELECT @FieldInt AS [FieldInt], @FieldString AS [FieldString], @FieldDateTime AS [FieldDateTime]",
	new {FieldInt = 1, FieldString = "test", FieldDateTime = DateTime.Now}).ToArray();

Want to deserialize a type manually? No problem!

public class MyClass : ICustomDeserialized
{
	public int FieldInt { get; set; }

	public string FieldString { get; set; }

	public DateTime? FieldDateTime { get; set; }

	public void Deserialize(IDataRecord record)
	{
		FieldInt = Xyapper.Internal.TypeConverter.ToType<int>(record["FieldInt"]);
		FieldString = Xyapper.Internal.TypeConverter.ToType<string>(record["FieldString"]);
		FieldDateTime = Xyapper.Internal.TypeConverter.ToType<DateTime?>(record["FieldDateTime"]);
	}
}

Too lazy even to declare a type? You're welcome!

var dataTable = Connection.XGetDataTable(
	"SELECT @FieldInt AS [FieldInt], @FieldString AS [FieldString], @FieldDateTime AS [FieldDateTime]",
	new {FieldInt = 1, FieldString = "test", FieldDateTime = DateTime.Now});

var generatedCode = Xyapper.CodeGenerator.GenerateClassCode(dataTable, "MyClass");

Xyapper.MsSql

Microsoft SQL Server specific extensions for Xyapper

NuGet Version and Downloads count alternate text is missing from this package README image

Usage examples

Create a SQL connection singleton factory (for Xyapper.MsSql only SqlConnection will fit)

public static SqlConnection Connection
{
	get
	{
		return new SqlConnection("Data Source=localhost;Database=mydatabase;User Id=sa;Password=mypassword");
	}
}

Bulk copy an array to database

Connection.XBulkCopy(tableName: "DestinationTableName", data: myDataArray, schema: "dbo", createTableIfNotExists: true, addColumnsIfNotExist: true);

Bulk copy a DataTable to database

Connection.XBulkCopy(tableName: "DestinationTableName", dataTable: myDataTable , schema: "dbo", createTableIfNotExists: true, addColumnsIfNotExist: true);

Get columns list of a table in DB

var columns = Connection.XGetColumns("MyTableName", "dbo");

Check if table exists

var tableExists = Connection.XCheckIfTableExists("MyTableName", "dbo");

Create a new table in DB

Connection.XCreateTable("MyNewTable", new List<SqlColumn>()
{
	new SqlColumn() {ColumnName = "Column1", ColumnType = SqlDbType.Int},
	new SqlColumn() {ColumnName = "Column2", ColumnType = SqlDbType.VarChar, ColumnSize = 100}
}, "dbo");

Drop a table in DB

Connection.XDropTable("MyNewTable", "dbo");

Add a column to table

Connection.XAddColumn("MyTableName", new SqlColumn() {ColumnName = "NewColumn", ColumnType = SqlDbType.Int});
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.19 603 11/28/2019
1.0.18 505 8/20/2019
1.0.17 483 8/20/2019
1.0.16 500 7/17/2019
1.0.15 463 7/17/2019
1.0.14 479 7/17/2019
1.0.13 520 6/20/2019
1.0.12 511 6/18/2019
1.0.11 489 6/18/2019
1.0.10 503 6/18/2019
1.0.9 494 6/17/2019
1.0.8 520 6/3/2019
1.0.7 517 5/29/2019
1.0.6 539 5/21/2019
1.0.5 563 5/21/2019
1.0.4 539 5/20/2019
1.0.3 513 5/17/2019
1.0.2 554 5/17/2019
1.0.1 534 5/15/2019
1.0.0 547 5/15/2019