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:
- [Chinese] Query extensions
- [Chinese] Dynamic LINQ
LinqSharp.EFCore provides enhancements to Entity Frameowk in the following ways:
- [Chinese] Data annotations for table design
- [Chinese] Data annotations for field formatting
- [Chinese] Compound query
- [Chinese] Custom translator
- [Chinese] Concurrency Resolving
- [Chinese] Agent query for Key-Value structure
- [Chinese] Direct handling
Supported | Out of support | |
---|---|---|
.NET | ||
.NET Standard | ||
Entity Framework Core |
You can install LinqSharp through NuGet:
dotnet add package LinqSharp
dotnet add package LinqSharp.EFCore
- Update dependencies.
- Update search extension method.
- Now, you can use the new syntax to search any field in a table or related tables.
- Enable nullable checking.
- Compatibility updates: NStandard - 0.70.0 - Update.
- Enable nullable checking.
- Fix some bugs.
- Rename FieldOption to AutoMode.
- Rename IFieldOptionScope to IAutoModeScope.
- Add new annotation RowLock to disable locked records from being changed or deleted.
- Add new annotation AutoMonthOnly to format DateTime / DateTimeOffset / DateOnly only keeping the year and month.
- Add these new extension methods to create intelligently tracked queries with specified behavior for DbContext.
- BeginRowLock
- BeginTimestamp
- BeginUserTrace
- Breaking Change: The length of Value in KeyValueEntity is set to 768 by default.
- Breaking Change: Change some internal class names.
- Rename IExtraFieldFilter to IAdvancedFieldFilter.
-
New Methods: Added Random() and RandomOrDefault() to get a random record.
-
Breaking Change: Columns marked by SpecialAutoAttribute cannot be modified manually, and their values can only be maintained by the engine.
This change will work better with the Update method provided by EFCore.
-
Experimental:
Some methods in LinqSharp.EFCore that do not depend on EntityFramework have been extracted to LinqSharp.EFCore.
Third-party libraries can use these methods more conveniently by referencing LinqSharp.EFCore.Core.
-
DirectQuery has been renamed to DirectQueryScope.
- New Feature: Added IExtraFieldFilter interface for more flexible field filtering.
- Compatibility updates: NStandard - 0.48.0 - Update, Ref.
- Compatibility updates: NStandard - 0.45.0 - Update, DateOnlyType and DateTimeType.
- Breaking Change: Adjusted some namespace names.
- Bug fixed: Null support for AllSame.
- Breaking Change: Adjusted some namespace names.
- Indexing / UniqueIndexing modified to lazy query.
- Two field filters have been added: DateOnlyRangeFilter, DateTimeRangeFilter.
- These methods has been marked as obsolete, please use FilterBy(Func<,>, DateTimeRangeFilter) method instead:
- WhereAfter
- WhereBefore
- WhereBetween
- New Feature: Added FilterBy support for QueryHelper, IFieldFilter can now be applied directly to QueryHelper.
- New Feature: Added IFieldFilter for building field-based conditions, support dynamic building.
- New Feature: Added IFieldLocalFilter / IFieldQueryFilter for building field-based conditions.
- New Feature: Added IEnumerableExtensions.Index for creating indexes to provide faster queries.
- IQueryFilter no longer needs to implement local filter methods. Implement ILocalFilter if needed.
- Filter extension now supports executing multiple filters sequentially.
- Dynamic Query: QueryHelper provides property chain analysis to support dynamic query of Owned Entity.
- Optimized GroupByCount performance (takes about -35% in time), but planned to remove this method.
- Mark GroupByCount as Obsolete method, please use Chunk method instead.
- EFCore 6.0 and above: Not provided, use the native method.
- EFCore 5.0 and below: Code compatibility.
-
Provides two new data annotations:
- [AutoCreatedBy]: Automatically maintain user information for created entries.
- [AutoUpdatedBy]: Automatically maintain user information for updated entries.
- Make DbContext implement IUserTraceable interface, see [documentation](https://github.com/zmjack/LinqSharp/blob/master/docs/cn/ef-data-annotations-2.md for details #Automatic maintenance of user information for operation entries).
-
[Breaking Change] QuickDataView has been removed, please use IEnumerableExtensions.FullJoin instead.
-
[Breaking Change] IEntity.AcceptBut has been removed.
-
[Breaking Change] Change the method name IQueryableExtensions.ToSql to ToQueryString.
- EFCore 5.0 and above: Not provided, use the native method.
- EFCore 3.1 and below: Code compatibility.
- [Breaking Change] The Ensure methods have been removed, and AddOrUpdate methods are recommended to be used instead.
- [Breaking Change] CustomDatabaseFacade has been removed.
- Provide EntityMonitoringFacade for monitoring table CRUD to facilitate writing other docking operations.
-
Some methods in AutoAttribute has been changed:
/* public abstract object Format(object entity, object value); */ public abstract object Format(object entity, Type propertyType, object value);
- Change the method name XWhere to Filter.
- Allows to create a stand-alone filter IQueryFilter and query in the Filter method.
-
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; }
- To avoid naming conflicts, IndexAttribute has been renamed to IndexFieldAttribute.
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:
dotnet add package Northwnd
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.ToQueryString();
Console.WriteLine(sql);
}
The variable sql is:
SELECT "x"."ShipperID", "x"."CompanyName", "x"."Phone"
FROM "Shippers" AS "x"
WHERE "x"."CompanyName" = 'Speedy Express';