FmgLib.Orm.DbHelper.SQLite
1.0.4.1
See the version list below for details.
dotnet add package FmgLib.Orm.DbHelper.SQLite --version 1.0.4.1
NuGet\Install-Package FmgLib.Orm.DbHelper.SQLite -Version 1.0.4.1
<PackageReference Include="FmgLib.Orm.DbHelper.SQLite" Version="1.0.4.1" />
paket add FmgLib.Orm.DbHelper.SQLite --version 1.0.4.1
#r "nuget: FmgLib.Orm.DbHelper.SQLite, 1.0.4.1"
// Install FmgLib.Orm.DbHelper.SQLite as a Cake Addin #addin nuget:?package=FmgLib.Orm.DbHelper.SQLite&version=1.0.4.1 // Install FmgLib.Orm.DbHelper.SQLite as a Cake Tool #tool nuget:?package=FmgLib.Orm.DbHelper.SQLite&version=1.0.4.1
DbHelper is a modern object-relational mapper (O/RM) for .NET. It supports updates, and schema migrations. DbHelper works with SQL Server, SQLite, MySQL, PostgreSQL, and Oracle through a provider plugin API.
To use it, you first need to download the FmgLib.Orm.DbHelper.SQLite
package from Nuget.
You can easily include the package in your application in Program.cs. Example usage is as follows:
using FmgLib.Orm.DbHelper.SQLite;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
await builder.Services.DbEntegrationSQLiteAsync(builder.Configuration.GetConnectionString("SQLITE")); // OR
// builder.Services.DbEntegrationSQLite(builder.Configuration.GetConnectionString("SQLITE")); // Asynchronous and synchronous usage is up to your preference.
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
builder.Services.DbEntegrationSQLite(builder.Configuration.GetConnectionString("SQLITE"));
we ensure integration by adding this line to your code.
Let's create an example entity:
using FmgLib.Orm.Common;
namespace FmgLib.TestWeb.Models;
[Table("PRODUCTS")]
public class Product : IDbEntity
{
[Column(IsNotNull = true, IsPrimaryKey = true, IsAutoIncrement = true)]
public int Id { get; set; }
[Column(IsNotNull = true)]
public string ProductName { get; set; }
[Column(IsNotNull = true)]
public double Price { get; set; }
public int CategoryId { get; set; }
}
You can specify a special name for the table that will be created on the database side for the entity you created with the table attribute.
[Table(TableName="TABLE_NAME")]
We can make special definitions for the column that will be created on the database side for the property you created with the column attribute.
[Column(IsNotNull = true, IsPrimaryKey = true, IsAutoIncrement = true)]
The entity to be created must be implemented from the IDbEntity interface. Entities that are not implemented through the IDbEntity interface will not be migrated.
To benefit from these attributes, you will need to download the FmgLib.Orm.Common
package from Nuget.
Let's take an example code:
using FmgLib.Orm.DbHelper;
using FmgLib.Orm.DbHelper.SQLite;
using FmgLib.TestWeb.Models;
using Microsoft.AspNetCore.Mvc;
namespace FmgLib.TestWeb.Controllers
{
public class HomeController : Controller
{
private readonly ISQLiteDbCenter _dbCenter;
public HomeController(ISQLiteDbCenter dbCenter)
{
_dbCenter = dbCenter;
}
public IActionResult Index()
{
var queryGenerate = new SqlQueryGenerate();
List<Product> products = new List<Product>();
for (int i = 1; i <= 100; i++)
{
var product = new Product
{
ProductName = $"Deneme Test {i * 4}",
Price = i * 8,
CategoryId = i,
};
products.Add(product);
}
var sqliteinsert = queryGenerate.SqlInsertRange(products); // Insert Range Operation
var resultInsertSS = _dbCenter.SendQuery<Product, int>(sqliteinsert); // Send SQL Query
var queryString = queryGenerate.GetQuery<Product>(x => x.Price >= 200, x => x.Price, Orm.Common.OrderedType.Desc);
var result = _dbCenter.SendQuery<Product, List<Product>>(queryString);
return View();
}
}
}
In this code, methods to generate SQL are provided to us via the 'queryGenerate' object. SqlInsertRange
function takes List as parameter. As a result, the SQL query is returned.
GetQuery<TEntity>
method helps for listing. As the first parameter, you can write your WHERE condition with a lambda expression. As the second parameter, the Order operation, that is, the sorting criterion, is determined (lambda is selected with an expression.) and ASC is handled by default. If you want to perform the reverse operation, you can give OrderedType
as the third parameter.
All written SQL queries are sent to the database with the SendQuery<TEntity, TResult>(string query)
method of the _dbCenter
object. TEntity
here represents the Model to be processed and TResult
represents the value to be returned.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net6.0
- FmgLib.Orm.DbHelper (>= 1.0.4.2)
- System.Data.SQLite.Core (>= 1.0.118)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.