Skip to content

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

zmjack/LinqSharp

Repository files navigation

LinqSharp

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:


Supported versions of .NET

Frameworks Versions
.NET Static Badge Static Badge Static Badge Static Badge
.NET Standard Static Badge Static Badge

Supported versions of Entity Framework

Entity Framework Core Versions
Supported Static Badge Static Badge Static Badge Static Badge
Preparing to end Static Badge

We are preparing to discontinue support for LinqSharp.EFCore - EF2.1 because projects that reference it may encounter the following error when compiling:

System.Runtime.CompilerServices.Unsafe doesn't support netcoreapp2.1. Consider updating your TargetFramework to netcoreapp3.1 or later.


Install

You can install LinqSharp through NuGet

dotnet add package LinqSharp
dotnet add package LinqSharp.EFCore

Recent

Version 7.0.41 - EFCore

  • Enable nullable checking.
  • Fix some bugs.
  • Rename FieldOption to AutoMode.
  • Rename IFieldOptionScope to IAutoModeScope.

Version 7.0.37.17 - EFCore

  • 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.

Version 7.0.37

  • Rename IExtraFieldFilter to IAdvancedFieldFilter.

Version 7.0.36

  • 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.

Version 7.0.35

  • 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.

Version: 7.0.34

  • New Feature: Added IExtraFieldFilter interface for more flexible field filtering.

Version: 7.0.32

  • Compatibility updates: NStandard - 0.48.0 - Update, Ref.

Version: 7.0.30

  • Compatibility updates: NStandard - 0.45.0 - Update, DateOnlyType and DateTimeType.

Version: 7.0.27

  • Breaking Change: Adjusted some namespace names.
  • Bug fixed: Null support for AllSame.

Version: 7.0.24

  • Breaking Change: Adjusted some namespace names.

Version: 7.0.20

  • Indexing / UniqueIndexing modified to lazy query.

Version: 7.0.18.1

  • 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

Version: 7.0.17

  • New Feature: Added FilterBy support for QueryHelper, IFieldFilter can now be applied directly to QueryHelper.

Version: 7.0.13

  • New Feature: Added IFieldFilter for building field-based conditions, support dynamic building.

Version: 7.0.11

  • New Feature: Added IFieldLocalFilter / IFieldQueryFilter for building field-based conditions.

Version: 7.0.10

  • New Feature: Added IEnumerableExtensions.Index for creating indexes to provide faster queries.

Version: 7.0.9

  • IQueryFilter no longer needs to implement local filter methods. Implement ILocalFilter if needed.
  • Filter extension now supports executing multiple filters sequentially.

Version: 7.0.2

  • 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.

Version: 7.0

  • Provides two new data annotations:

  • [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.

Version: 6.0.16

  • [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.

Version: 6.0.14

  • 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);

Version: 6.0.6

  • Change the method name XWhere to Filter.
  • Allows to create a stand-alone filter IQueryFilter and query in the Filter method.

Version: 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; }

Version: 6.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

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';

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