LazySqlStandard.Engine 2.0.0-preview

This is a prerelease version of LazySqlStandard.Engine.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package LazySqlStandard.Engine --version 2.0.0-preview                
NuGet\Install-Package LazySqlStandard.Engine -Version 2.0.0-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.0.0-preview" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LazySqlStandard.Engine --version 2.0.0-preview                
#r "nuget: LazySqlStandard.Engine, 2.0.0-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.0.0-preview&prerelease

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

LazySql

Build status Maintenance

Nuget

LazySql is a micro ORM to simplify the interfacing between an application and a database.

⭐ Star me on GitHub — it motivates me a lot!

Compatibility

.NET

.NET .NET Framework .NET Standard
Version 6.0 4.8 2.0

Sql Server

Minimum version: 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);
}

This automatically generates the following SQL query in the background:

SELECT Id, Name, ... FROM Cars

Select some data in a table (with Expression)

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();

Or (if your object doesn't derive from LazyBase):

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

These two methods will generate the following SQL query:

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

Delete in database

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

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

Or (if your object doesn't derive from LazyBase):

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

These two methods will generate the following SQL query:

DELETE Cars WHERE id = 1

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));

Et voilà ()

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