This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using Z.EntityFramework.Extensions; // Don't forget to include this. | |
// Easy to use | |
context.BulkMerge(list); | |
// Easy to customize | |
context.BulkMerge(list, bulk => bulk.BatchSize = 100); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using Z.EntityFramework.Extensions; // Don't forget to include this. | |
// Easy to use | |
context.BulkSaveChanges(); | |
// Easy to customize | |
context.BulkSaveChanges(bulk => bulk.BatchSize = 100); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using Z.EntityFramework.Extensions; // Don't forget to include this. | |
// Easy to use | |
context.BulkUpdate(list); | |
// Easy to customize | |
context.BulkUpdate(list, bulk => bulk.BatchSize = 100); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using Z.EntityFramework.Plus; // Don't forget to include this. | |
var ctx = new EntitiesContext(); | |
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using Z.EntityFramework.Plus; // Don't forget to include this. | |
var ctx = new EntitiesContext(); | |
// The count is deferred and cached. | |
var count = ctx.Customers.DeferredCount().FromCache(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using Z.EntityFramework.Plus; // Don't forget to include this. | |
var ctx = new EntitiesContext(); | |
ctx.Filter<Post>(q => q.Where(x => !x.IsSoftDeleted)); | |
// SELECT * FROM Post WHERE IsSoftDeleted = false | |
var list = ctx.Posts.ToList(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using Z.EntityFramework.Plus; // Don't forget to include this. | |
var ctx = new EntitiesContext(); | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using Z.EntityFramework.Plus; // Don't forget to include this. | |
var ctx = new EntitiesContext(); | |
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ctx = new EntitiesContext(); | |
ctx.Customers.AddRange(listToAdd); // add | |
ctx.Customers.RemoveRange(listToRemove); // remove | |
listToModify.ForEach(x => x.DateModified = DateTime.Now); // modify | |
// Easy to use | |
ctx.BulkSaveChanges(); | |
// Easy to customize |