Xyapper 1.0.3
See the version list below for details.
dotnet add package Xyapper --version 1.0.3
NuGet\Install-Package Xyapper -Version 1.0.3
<PackageReference Include="Xyapper" Version="1.0.3" />
paket add Xyapper --version 1.0.3
#r "nuget: Xyapper, 1.0.3"
// Install Xyapper as a Cake Addin #addin nuget:?package=Xyapper&version=1.0.3 // Install Xyapper as a Cake Tool #tool nuget:?package=Xyapper&version=1.0.3
Xyapper
A lightweight ORM wrapper for ADO.NET providers
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
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 | Versions 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. |
-
.NETStandard 2.0
- Microsoft.Extensions.Logging (>= 2.2.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Xyapper:
Package | Downloads |
---|---|
Xyapper.MsSql
MS Sql extension for Xyapper with T-SQL specific functions such as bulk copy and others. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.19 | 809 | 11/28/2019 |
1.0.18 | 686 | 8/20/2019 |
1.0.17 | 665 | 8/20/2019 |
1.0.16 | 672 | 7/17/2019 |
1.0.15 | 648 | 7/17/2019 |
1.0.14 | 658 | 7/17/2019 |
1.0.13 | 718 | 6/20/2019 |
1.0.12 | 694 | 6/18/2019 |
1.0.11 | 662 | 6/18/2019 |
1.0.10 | 681 | 6/18/2019 |
1.0.9 | 704 | 6/17/2019 |
1.0.8 | 753 | 6/3/2019 |
1.0.7 | 671 | 5/29/2019 |
1.0.6 | 716 | 5/21/2019 |
1.0.5 | 718 | 5/21/2019 |
1.0.4 | 748 | 5/20/2019 |
1.0.3 | 681 | 5/17/2019 |
1.0.2 | 706 | 5/17/2019 |
1.0.1 | 668 | 5/15/2019 |
1.0.0 | 653 | 5/15/2019 |