Git Product home page Git Product logo

entityframework-plus's Introduction

This library is under construction. New features are added weekly.

Use .NET Entity Framework Extensions for stable version.

##Entity Framework Bulk Operations & Utilities##

Download

Version NuGet NuGet Install
Z.EntityFramework.Plus.EF7 PM> Install-Package Z.EntityFramework.Plus.EF7
Z.EntityFramework.Plus.EF6 PM> Install-Package Z.EntityFramework.Plus.EF6
Z.EntityFramework.Plus.EF5 PM> Install-Package Z.EntityFramework.Plus.EF5

Full & Standalone Version Downloads

Features

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).DelayedCount().FromCache("countries", "states");

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

Learn more

Query Delayed

Delay 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.DelayedCount().FromCache();

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

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

Learn more

Query Filter

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

Support

Global Filter

public class EntityContext : DbContext
{
        public EntityContext() : base("MyDatabase")
        {
            // CONFIGURE all your filters for all context
            this.Filter<Customer>(x => x.Where(c => c.IsActive));
        }
        
        public DbSet<Customer> Customers { get; set; }
}

// SELECT * FROM Customer WHERE IsActive = true
var ctx = new EntityContext();
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>(custom.EnumValue, x => x.Where(c => c.IsActive), false);

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

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).DelayedFirstOrDefault().FutureValue();
var futureCustomerCount = db.Customers.Where(x => x.IsActive).DelayedCount().FutureValue();

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

Learn more

Query IncludeQuery

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.Include(x => x.Comments.Where(x => x.IsActive));

Learn more

Audit

Entity Framework allow to save changes but doesn’t log what change has been made in the Change Tracker. Audit allow to capture every changes made on entities and relations saved to your underling database.

Support:

  • Identity
  • All kind of entity/inheritance (Complex Type, TPC, TPH, TPT)
  • All kind of relations (Many to Many, One to Many, One to One, etc.)
  • Audit AutoSaving
var ctx = new EntityContext();

// ... ctx changes ...
var audit = new Audit();
ctx.SaveChanges(audit);

// You have now access to all captured informations
var entries = audit.Entries;
foreach(var entry in entries)
{
    foreach(var property in entry.Properties)
    {
    }
}

Want to save audit entries automatically after every SaveChanges(audit) call?

// ADD AuditEntry && AuditEntryProperty to your context or use your own entity
AuditManager.DefaultConfiguration.AutoSaveAction = (context, audit) =>
    (context as EntityContext).AuditEntries.AddRange(audit.Entries);

Learn more

FREE vs PRO

Every month, a new monthly trial of the PRO Version is available to let you evaluate all its features without limitations.

Features FREE Version PRO Version
Audit Yes Yes
Query Batch Yes Yes
Query Cache Yes Yes
Query Delayed Yes Yes
Query Filter Yes Yes
Query Future Yes Yes
Query IncludeOptimize Yes Yes
Query IncludeQuery Yes Yes
Commercial License Yes Yes
Royalty-Free Yes Yes
Support & Upgrades (1 year) No Yes
Learn more about the PRO Version (Not available until 2016 Q1)

(Compatible with license from .NET Entity Framework Extensions)

More Projects

Need more info? [email protected]

Contact our outstanding customer support for any request. We usually answer within the next business day, hour, or minutes!

entityframework-plus's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.