Include Optimized

Introduction

IncludeOptimized allows you to optimize the query generated by EF by executing multiple smaller queries instead of executing only one monster SQL.

Why IncludeOptimized?

Common Scenarios:

  • The SQL generated by Entity Framework is too big and take several seconds or minutes to be executed.

Example

// SELECT * FROM Order WHERE....
// SELECT * FROM OrderItem WHERE EXISTS (/* previous query */) AND ...
// SELECT * FROM DeliveryItems WHERE EXISTS (/* previous query */) AND ...

var orders = ctx.Orders
.Where(x => x.OrderId == myOrderID) // 1 orders, 20 columns
.IncludeOptimized(x => x.Items) // 20 items, 10 columns
.IncludeOptimized(x => x.DeliveredItems) // 10 items, 10 columns
.ToList();

Supported Libraries

Library Type EF Version Support Doc Features
Z.EntityFramework.Plus FREE EF5
EF6
EF Core
< 1 Day Yes Audit
Batch Delete
Batch Update
Cache
Deferred Query
Filter
Future
Include Filter
Include Optimized

Unsuported Libraries

Use this library at your risk!

Library Type EF Version Support Doc Features
EFUtilities FREE EF5
EF6
No No Bulk Insert
Batch Delete
Batch Update
Include Optimized