Skip to content
/ LinqSharp Public
forked from zmjack/LinqSharp

LinqSharp is a smarter linq extension. It allows you to write simpler code to generate complex queries.

License

Notifications You must be signed in to change notification settings

hnjm/LinqSharp

 
 

Repository files navigation

LinqSharp

Other Language: 中文


LinqSharp is an open source LINQ extension library that allows you to write simple code to generate complex queries, including query extensions and dynamic query generation.

LinqSharp.EFCore is an enhanced library for EntityFramework, providing more data annotations, database functions, and custom storage rules, etc.


LinqSharp provides enhancements to LINQ in the following ways:

LinqSharp.EFCore provides enhancements to Entity Frameowk in the following ways:

  • [no documentation yet, but have chinese version] Data annotations for table design
  • [no documentation yet, but have chinese version]] Data annotations for field standard
  • [no documentation yet] Function mapping
  • [no documentation yet] Column storage agent
  • [no documentation yet] Data calculation and audit

Supported version of Entity Framework:

  • Entity Framework Core 3.1
  • Entity Framework Core 2.1+

**Restricted supported version of Entity Framework: **

  • Entity Framework Core 3.0+ : 1 failed.

Install

You can install LinqSharp through NuGet

Package Manager

Install-Package LinqSharp
Install-Package LinqSharp.EFCore

.NET CLI

dotnet add package LinqSharp
dotnet add package LinqSharp.EFCore

Try using the sample database

Northwnd, an early sample database shipped with SQL Server, describes a simple "enterprise sales network" scenario.

The database includes a network of employees, orders, and suppliers.


The NuGet version of Northwnd is a SQLite database (Code First).

Repository:https://github.com/zmjack/Northwnd


You can install Northwnd through NuGet

Install-Package Northwnd
dotnet add package Northwnd

Then, you can try LinqSharp:

using (var context = NorthwndContext.UseSqliteResource())
{
    ...
}

For example:

using (var sqlite = NorthwndContext.UseSqliteResource())
{
    var query = sqlite.Shippers.Where(x => x.CompanyName == "Speedy Express");
    var sql = query.ToSql();
}

The variable sql is:

SELECT "x"."ShipperID", "x"."CompanyName", "x"."Phone"
FROM "Shippers" AS "x"
WHERE "x"."CompanyName" = 'Speedy Express';

Function Provider Supports

.NET Function Jet MySql Oracle PostgreSQL Sqlite SqlServer
DbFunc.Random ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
DbFunc.Concat ✔️ ✔️ ✔️ ✔️
DbFunc.DateTime ✔️ 🔘 🔘 ✔️

For example, EntityFramework can not translate this expression:

.Where(x => new DateTime(x.Year, x.Month, x.Day) > DateTime.Now);

So, we provide another function to support this:

.Where(x => DbFunc.DateTime(x.Year, x.Month, x.Day) > DateTime.Now);

If use MySQL, the generated SQL is:

WHERE STR_TO_DATE(CONCAT(`x`.`Year`, '-', `x`.`Month`, '-', `x`.`Day`), '%Y-%m-%d') > CURRENT_TIMESTAMP();

About

LinqSharp is a smarter linq extension. It allows you to write simpler code to generate complex queries.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.8%
  • Batchfile 0.2%