LazySqlStandard.Engine
2.1.1-preview
dotnet add package LazySqlStandard.Engine --version 2.1.1-preview
NuGet\Install-Package LazySqlStandard.Engine -Version 2.1.1-preview
<PackageReference Include="LazySqlStandard.Engine" Version="2.1.1-preview" />
paket add LazySqlStandard.Engine --version 2.1.1-preview
#r "nuget: LazySqlStandard.Engine, 2.1.1-preview"
// 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
anddynamic
types! - Namespace fixed
- Support of SqlCredential
Packages
NuGet | Downloads | .NET | .NET Framework | .NET Standard | Sql Server |
---|---|---|---|---|---|
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.
Links
- My Web site: https://floriandussault.dev/
- Documentation: https://lazysql.floriandussault.dev/
Product | Versions 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. |
-
.NETFramework 4.8
- Microsoft.Data.SqlClient (>= 5.0.1)
- System.Data.SqlClient (>= 4.8.5)
-
.NETStandard 2.1
- Microsoft.Data.SqlClient (>= 5.0.1)
- System.Data.SqlClient (>= 4.8.5)
-
net6.0
- Microsoft.Data.SqlClient (>= 5.0.1)
- System.Data.SqlClient (>= 4.8.5)
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 |