LazySqlStandard.Engine 2.1.1-preview

This is a prerelease version of LazySqlStandard.Engine.
dotnet add package LazySqlStandard.Engine --version 2.1.1-preview                
NuGet\Install-Package LazySqlStandard.Engine -Version 2.1.1-preview                
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="LazySqlStandard.Engine" Version="2.1.1-preview" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LazySqlStandard.Engine --version 2.1.1-preview                
#r "nuget: LazySqlStandard.Engine, 2.1.1-preview"                
#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 LazySqlStandard.Engine as a Cake Addin
#addin nuget:?package=LazySqlStandard.Engine&version=2.1.1-preview&prerelease

// Install LazySqlStandard.Engine as a Cake Tool
#tool nuget:?package=LazySqlStandard.Engine&version=2.1.1-preview&prerelease                

LazySql

LazySql is a micro ORM to simplify the interfacing between an application and a Sql Server Database.

Whats new in 2.1.1-preview?

  • System.Data.SqlClient from 4.8.4 to 4.8.5 (Security)
  • Support of object and dynamic types!
  • Namespace fixed
  • Support of SqlCredential

Packages

Build status

NuGet Downloads .NET .NET Framework .NET Standard Sql Server
LazySqlStandard.Engine LazySqlStandard.Engine 6.0 4.8 2.0 > Sql Server 2012

How to use it?

First of all, the initialization

LazySql uses a singleton, so you only have to initialise the client once.

LazyClient.Initialize("Server=my-server\SQL2019;Database=MyDataBase;");

Select all the data in a table

foreach (Car car in LazyClient.Select<Car>()) {
   Console.WriteLine(car.Name);
}

Select some data in a table with Expression (WHERE)

foreach (Car car in LazyClient.Select<Car>().Where(c=>c.Country == "FR" && c.Enabled).OrderBy(c=>c.Name)) {
   Console.WriteLine(car.Name);
}

This automatically generates the following SQL query in the background:

SELECT Id, Name, ... FROM Cars WHERE Country = 'FR' AND Enabled = 1 ORDER BY Name

Update in database

If your object is derived from LazyBase, you can easily update it:

Car car = new Car() {Id = 1, Name = "Second Car"};
car.Update();

This will generate the following SQL query:

UPDATE Cars SET Name = 'Second Car' WHERE id = 1

Update multiple rows in database

Car updateCar = new Car() {Name = "New Name"};
LazyClient.Update<Car>(updateCar, c=>c.Name == null || Id = 0);

This will generate the following SQL query:

UPDATE Cars SET Name = 'New Name' WHERE Name IS NULL OR Id = 0

Delete in database

If your object is derived from LazyBase, you can easily delete it:

Car car = new Car() {Id = 1};
car.Delete();

This will generate will generate the following SQL query:

DELETE Cars WHERE id = 1

Delete multiple rows in database

LazyClient.Delete<Car>(c=>!c.Enabled);

This will generate will generate the following SQL query:

DELETE Cars WHERE Enabled = 0

And more...

Stored Procedure

StoredProcedureResult result = LazyClient.StoredProcedure("my_procedure",
            new SqlArguments()
               .Add("@FirstName", SqlType.NVarChar, "Florian")
               .Add("@Age", SqlType.Int, 40)
               .AddOut("@Id", SqlType.Int) // OUTPUT PARAMETER
        );

// Get return value (RETURN)
Console.WriteLine($"Result: {result.ReturnValue}");
// Get Output value
Console.WriteLine($"Result: {result.Output.Id}");

// Get first table with dynamic types
IEnumerable<dynamic> dynamicValues = result.Tables[0].Parse();
// Get second table with an object type
IEnumerable<Profil> result.Tables[1].Parse<Profil>();

Bulk Insert

List<Car> cars = GetCars();
LazyClient.BulkInsert(cars);

ExecuteNonQuery method

int affectedRows = LazyClient.ExecuteNonQuery("DELETE FROM web_users");

ExecuteScalar method

string firstName = LazyClient.ExecuteNonQuery<string>("SELECT firstname FROM web_users WHERE Id = @Id", new SqlArgument("@Id", SqlType.Int, 50));

Documentation

Click here for the full documentation, F.A.Q. and Release Note !

License

LazySql is licensed under the terms of the MIT license and is available for free.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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
2.1.1-preview 124 11/27/2022
2.0.0-preview 142 11/18/2022