LinqSharp
LinqSharp copied to clipboard
LinqSharp is a smarter linq extension. It allows you to write simpler code to generate complex queries.
LinqSharp
Other Language: 中文
Current work in progress: Optimize PreQuery queries.
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:
- [No documentation yet, but have chinese version] Query extension
- [No documentation yet, but have chinese version] Dynamic LINQ
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: EF Core 6.0 / 5.0 / 3.1 / 3.0 / 2.1
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
Recent
After 2.1.106 | 3.0.106 | 3.1.106 | 5.0.6 | 6.0.6
- Change the method name XWhere to Filter.
- Allows to create a stand-alone filter IQueryFilter and query in the Filter method.
After 2.1.104 | 3.0.104 | 3.1.104 | 5.0.4 | 6.0.4
-
Simplify the code writing for Provider.
-
After 2.1.104 | 3.0.104 | 3.1.104 | 5.0.4 | 6.0.4 .
Old:
[Provider(typeof(JsonProvider<NameModel>))]
public NameModel NameModel { get; set; }
New:
[JsonProvider]
public NameModel NameModel { get; set; }
After 2.1.80 | 3.0.80 | 3.1.80 | 5.0.0 | 6.0.0
- To avoid naming conflicts, IndexAttribute has been renamed to IndexFieldAttribute.
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();