Entity Framework Plus A FREE & Open Source library to enhance EF6 and EF Core


Downloaded more than
0
times !
// DELETE all users which are inactive for 2 years
ctx.Users.Where(x =>
x.LastLoginDate < DateTime.Now.AddYears(-2))
.Delete();

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




Why does EF Plus now depends on EF Extensions?

EF Plus is FREE for you and will always be!

However, maintaining and developing a free library for a company is very expensive.


> 1,000+ Requests answered per year
> $100,000 USD investment per year
> 400 Commits per year
> 100 Releases per year


Auditing

Improve security and know what, when and who did a changes in the context.

  • AutoSave audit values in the database
  • Keep track of SoftDelete entities
  • Filter events you desire
  • Include entity type you desire
  • Format value in your specific format
Auditing Example
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)
 {
 }
}

Delete without loading entities

Delete rows from LINQ Query in a single database round trip without loading entities in the context.

  • Use Async methods to make your application responsive
  • Use batch size to improve performance
  • Use batch delay interval to reduce server load
  • Use Intercept to customize DbCommand
Batch Delete Example
/ DELETE all users inactive for 2 years
var date = DateTime.Now.AddYears(-2);
ctx.Users.Where(x => x.LastLoginDate < date)
    .Delete();

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

Update without loading entities

Update rows from LINQ Query in a single database round trip without loading entities in the context.

  • Use Async methods to make your application responsive
  • Use Intercept to customize DbCommand
Batch Update Example
// UPDATE all users inactive for 2 years
var date = DateTime.Now.AddYears(-2);
ctx.Users.Where(x => x.LastLoginDate < date)
    .Update(x => new User() { IsSoftDeleted = 1 });

Second Level Cache

Improve application performance and reduce sql server load by using a second level caching.

  • Use Cache Tag to expire cache
  • Use Cache Policy to control caching
Query Cache Example
// The first call perform a database round trip
var countries1 = ctx.Countries.FromCache().ToList();

// Subsequent calls will take the value from the memory instead
var countries2 = ctx.Countries.FromCache().ToList();

Filtering

Improve your context extensibility and create filters to query only what's really available.

  • Create Multi-Tenancy application
  • Exclude soft deleted record
  • Filter record by security access
Query Filter Example
QueryFilterManager.Filter<Post>
    (q => q.Where(x => !x.IsSoftDeleted));

var ctx = new EntitiesContext();

// SELECT * FROM Post WHERE IsSoftDeleted = false
var list = ctx.Posts.ToList();

Future & FutureValue

Delay queries execution and batch all queries in a single database round trip.

  • Query Future
  • Query Future Value
  • Query Future Value Deferred
  • Include entity types you desire
  • Format values in your specific format
Query Future Example
// CREATE a pending list of future queries
var futureCountries = db.Countries.Where(x => x.IsActive).Future();
var futureStates = db.States.Where(x => x.IsActive).Future();

// TRIGGER all pending queries in one database round trip
// SELECT * FROM Country WHERE IsActive = true;
// SELECT * FROM State WHERE IsActive = true
var countries = futureCountries.ToList();

// futureStates is already resolved and contains the result
var states = futureStates.ToList();

Filter included related entities

Overcome Include method limitations by filtering included related entities.

  • Child entities with IncludeFilter
  • Improve performance with IncludeOptimized
Query IncludeFilter Example
// LOAD orders and the first 10 active related entities.
var list = ctx.Orders.IncludeFilter(x => x.Items
        .Where(y => !y.IsSoftDeleted)
        .OrderBy(y => y.Date)
        .Take(10)
    )
    .ToList();