• Stars
    star
    2,187
  • Rank 20,221 (Top 0.5 %)
  • Language
    C#
  • License
    MIT License
  • Created over 8 years ago
  • Updated 16 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more

Library Powered By

This library is powered by Entity Framework Extensions

Entity Framework Extensions

Entity Framework Plus

Improve Entity Framework performance and overcome limitations with MUST-HAVE features

Download

Full Version NuGet NuGet Install
Z.EntityFramework.Plus.EFCore download PM> Install-Package Z.EntityFramework.Plus.EFCore
Z.EntityFramework.Plus.EF6 download PM> Install-Package Z.EntityFramework.Plus.EF6
Z.EntityFramework.Plus.EF5 download PM> Install-Package Z.EntityFramework.Plus.EF5

More download options (Full and Standalone Version)

Features


Bulk Operations only available with Entity Framework Extensions

  • BulkSaveChanges
  • BulkInsert
  • BulkUpdate
  • BulkDelete
  • BulkMerge

Batch Delete

Deletes multiples rows in a single database roundtrip and without loading entities in the context.

// using Z.EntityFramework.Plus; // Don't forget to include this.

// DELETE all users which has been inactive for 2 years
ctx.Users.Where(x => x.LastLoginDate < DateTime.Now.AddYears(-2))
         .Delete();

// DELETE using a BatchSize
ctx.Users.Where(x => x.LastLoginDate < DateTime.Now.AddYears(-2))
         .Delete(x => x.BatchSize = 1000);

Support: EF5, EF6, EF Core

Learn more

Batch Update

Updates multiples rows using an expression in a single database roundtrip and without loading entities in the context.

// using Z.EntityFramework.Plus; // Don't forget to include this.

// UPDATE all users which has been inactive for 2 years
ctx.Users.Where(x => x.LastLoginDate < DateTime.Now.AddYears(-2))
         .Update(x => new User() { IsSoftDeleted = 1 });

Support: EF5, EF6, EF Core

Learn more

Query Cache

Query cache is the second level cache for Entity Framework.

The result of the query is returned from the cache. If the query is not cached yet, the query is materialized and cached before being returned.

You can specify cache policy and cache tag to control CacheItem expiration.

Support:

Cache Policy

// The query is cached using default QueryCacheManager options
var countries = ctx.Countries.Where(x => x.IsActive).FromCache();

// (EF5 | EF6) The query is cached for 2 hours
var states = ctx.States.Where(x => x.IsActive).FromCache(DateTime.Now.AddHours(2));

// (EF7) The query is cached for 2 hours without any activity
var options = new MemoryCacheEntryOptions() { SlidingExpiration = TimeSpan.FromHours(2)};
var states = ctx.States.Where(x => x.IsActive).FromCache(options);

Cache Tags

var states = db.States.Where(x => x.IsActive).FromCache("countries", "states");
var stateCount = db.States.Where(x => x.IsActive).DeferredCount().FromCache("countries", "states");

// Expire all cache entry using the "countries" tag
QueryCacheManager.ExpireTag("countries");

Support: EF5, EF6, EF Core

Learn more

Query Deferred

Defer the execution of a query which is normally executed to allow some features like Query Cache and Query Future.

// Oops! The query is already executed, we cannot use Query Cache or Query Future features
var count = ctx.Customers.Count();

// Query Cache
ctx.Customers.DeferredCount().FromCache();

// Query Future
ctx.Customers.DeferredCount().FutureValue();

All LINQ extensions are supported: Count, First, FirstOrDefault, Sum, etc.

Support: EF5, EF6, EF Core

Learn more

Query Filter

Filter query with predicate at global, instance or query level.

Support:

Global Filter

// CREATE global filter
QueryFilterManager.Filter<Customer>(x => x.Where(c => c.IsActive));

var ctx = new EntityContext();

// TIP: Add this line in EntitiesContext constructor instead
QueryFilterManager.InitilizeGlobalFilter(ctx);

// SELECT * FROM Customer WHERE IsActive = true
var customer = ctx.Customers.ToList();

Instance Filter

var ctx = new EntityContext();

// CREATE filter
ctx.Filter<Customer>(x => x.Where(c => c.IsActive));

// SELECT * FROM Customer WHERE IsActive = true
var customer = ctx.Customers.ToList();

Query Filter

var ctx = new EntityContext();

// CREATE filter disabled
ctx.Filter<Customer>(CustomEnum.EnumValue, x => x.Where(c => c.IsActive), false);

// SELECT * FROM Customer WHERE IsActive = true
var customer = ctx.Customers.Filter(CustomEnum.EnumValue).ToList();

Support: EF5, EF6, EF Core

Learn more

Query Future

Query Future allow to reduce database roundtrip by batching multiple queries in the same sql command.

All future query are stored in a pending list. When the first future query require a database roundtrip, all query are resolved in the same sql command instead of making a database roundtrip for every sql command.

Support:

Future

// GET the states & countries list
var futureCountries = db.Countries.Where(x => x.IsActive).Future();
var futureStates = db.States.Where(x => x.IsActive).Future();

// TRIGGER all pending queries (futureCountries & futureStates)
var countries = futureCountries.ToList();

FutureValue

// GET the first active customer and the number of avtive customers
var futureFirstCustomer = db.Customers.Where(x => x.IsActive).DeferredFirstOrDefault().FutureValue();
var futureCustomerCount = db.Customers.Where(x => x.IsActive).DeferredCount().FutureValue();

// TRIGGER all pending queries (futureFirstCustomer & futureCustomerCount)
Customer firstCustomer = futureFirstCustomer.Value;

Support: EF5, EF6, EF Core

Learn more

Query IncludeFilter

Entity Framework already support eager loading however the major drawback is you cannot control what will be included. There is no way to load only active item or load only the first 10 comments.

EF+ Query Include make it easy:

var ctx = new EntityContext();

// Load only active comments
var posts = ctx.Post.IncludeFilter(x => x.Comments.Where(x => x.IsActive));

Support: EF6, EF Core

Learn more

Query IncludeOptimized

Improve SQL generate by Include and filter child collections at the same times!

var ctx = new EntityContext();

// Load only active comments using an optimized include
var posts = ctx.Post.IncludeOptimized(x => x.Comments.Where(x => x.IsActive));

Support: EF5, EF6, EF Core

Learn more

Audit

Allow to easily track changes, exclude/include entity or property and auto save audit entries in the database.

Support:

  • AutoSave Audit
  • Exclude & Include Entity
  • Exclude & Include Property
  • Format Value
  • Ignore Events
  • Property Unchanged
  • Soft Add & Soft Delete
// using Z.EntityFramework.Plus; // Don't forget to include this.

var ctx = new EntityContext();
// ... ctx changes ...

var audit = new Audit();
audit.CreatedBy = "ZZZ Projects"; // Optional
ctx.SaveChanges(audit);

// Access to all auditing information
var entries = audit.Entries;
foreach(var entry in entries)
{
    foreach(var property in entry.Properties)
    {
    }
}

AutoSave audit in your database

AuditManager.DefaultConfiguration.AutoSavePreAction = (context, audit) =>
    (context as EntityContext).AuditEntries.AddRange(audit.Entries);

Support: EF5, EF6, EF Core

Learn more

Useful links

Contribute

The best way to contribute is by spreading the word about the library:

  • Blog it
  • Comment it
  • Star it
  • Share it

A HUGE THANKS for your help.

More Projects

To view all our free and paid projects, visit our website ZZZ Projects.

More Repositories

1

html-agility-pack

Html Agility Pack (HAP) is a free and open-source HTML parser written in C# to read/write DOM and supports plain XPATH or XSLT. It is a .NET code library that allows you to parse "out of the web" HTML files.
C#
2,548
star
2

System.Linq.Dynamic.Core

The .NET Standard / .NET Core version from the System Linq Dynamic functionality.
HTML
1,500
star
3

Z.ExtensionMethods

C# Extension Methods | Over 1000 extension methods:
C#
1,350
star
4

EntityFramework.Extended

Add-on feature for Entity Framework
C#
1,339
star
5

EntityFramework.DynamicFilters

Global filtering for Entity Framework.
C#
501
star
6

EntityFramework-Effort

Entity Framework Effort is a powerful tool that enables a convenient way to create automated tests for Entity Framework based applications.
C#
431
star
7

Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
C#
424
star
8

System.Linq.Dynamic

[Deprecated] This is the Microsoft assembly for the .Net 4.0 Dynamic language functionality.
424
star
9

Dapper-Plus

Dapper Plus - High-Efficient Bulk Actions (Insert, Update, Delete, and Merge) for .NET
C#
367
star
10

EntityFramework-Extensions

Entity Framework Bulk Operations | Improve Entity Framework performance with Bulk SaveChanges, Insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL and SQLite.
C#
335
star
11

GraphDiff

GraphDiff is a library that allows the automatic update of a detached graph using Entity Framework code first.
C#
333
star
12

sqlfiddle3

New version based on vert.x and docker
JavaScript
324
star
13

sqlfiddle

JavaScript
275
star
14

findandreplace

fnr.exe - Find and Replace (FNR) is an open source tool to find and replace text in multiple files. It can quickly search through large numbers of files and also find the information using regular expressions specifying the form of what you want, instead of literal text.
C#
231
star
15

nmemory

NMemory is a lightweight non-persistent in-memory relational database engine that is purely written in C# and can be hosted by .NET applications.
C#
228
star
16

sqlfiddle2

New version of SQL Fiddle based on OpenIDM
JavaScript
194
star
17

Bulk-Operations

C# SQL Bulk Operations | High-performance C# bulk insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL, and SQLite.
C#
139
star
18

EntityFramework-Classic

Entity Framework Classic is a supported version of the latest EF6 codebase. It supports .NET Framework and .NET Core and overcomes some EF limitations by adding tons of must-haves built-in features.
C#
102
star
19

LINQ-Async

C# LINQ Async extension methods library for async/await task.
C#
100
star
20

Eval-SQL.NET

SQL Eval Function | Dynamically Evaluate Expression in SQL Server using C# Syntax.
C#
95
star
21

zzzcode.ai

AI Website for developers. Use ChatGPT to answer questions, write code, and more.
94
star
22

EntityFrameworkExtras

EntityFrameworkExtras provides some useful additions to EntityFramework such as executing Stored Procedures with User-Defined Table Types and Output Parameters.
C#
78
star
23

awesome-entity-framework-core

Awesome EF Core third party-libraries, documentation, and tutorials!
53
star
24

Dapper.Transaction

IDbTransaction extension methods for Dapper: A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..
C#
28
star
25

awesome-dapper

Awesome Dapper third party-libraries, documentation, and tutorials!
15
star
26

awesome-entity-framework-6

Awesome EF6 third party-libraries, documentation, and tutorials!
12
star
27

EntityFramework6-DotNetStandard

The support has been moved here: https://github.com/zzzprojects/EntityFramework-Classic
C#
12
star
28

Compiler-Expression.NET

C# Code Compiler | Code Analysis and Code Compiler for Eval-Expression.NET and Eval-SQL.NET
11
star
29

awesome-csharp-expression-evaluator

Awesome C#/.NET Expression Evaluator third party-libraries, documentation, and tutorials!
8
star
30

LinqToSql-Plus

LinqToSql Plus is a library that dramatically improves LinqToSql performances by using bulk and batch operations.
6
star
31

docs

4
star
32

learn-orm

learn-orm
C#
4
star
33

sqlite-provider

sqlite-provider
C
2
star
34

tutorial4.net

1
star