Skip to content

Instantly share code, notes, and snippets.

View JonathanMagnan's full-sized avatar

Jonathan Magnan JonathanMagnan

View GitHub Profile
List<AuditEntry> auditEntries = new List<AuditEntry>();
using (var ctx = new EntitiesContext())
{
ctx.BulkSaveChanges(list, operation =>
{
operation.UseAudit = true;
operation.BulkOperationExecuted = bulkOperation => auditEntries.AddRange(bulkOperation.AuditEntries);
});
}
// DELETE all customers that are inactive for more than two years
context.Customers
.Where(x => x.LastLogin < DateTime.Now.AddYears(-2))
.DeleteFromQuery();
// UPDATE all customers that are inactive for more than two years
context.Customers
.Where(x => x.Actif && x.LastLogin < DateTime.Now.AddYears(-2))
.UpdateFromQuery(x => new Customer {Actif = false});
var ctx = new EntitiesContext();
// Easy to use
ctx.BulkMerge(list);
// Easy to customize
context.BulkDelete(customers,
bulk => bulk.ColumnPrimaryKeyExpression = customer => customer.Code; });
var ctx = new EntitiesContext();
// Easy to use
ctx.BulkDelete(list);
// Easy to customize
context.BulkDelete(customers,
bulk => bulk.ColumnPrimaryKeyExpression = customer => customer.Code; });
var ctx = new EntitiesContext();
// Easy to use
ctx.BulkUpdate(list);
// Easy to customize
context.BulkUpdate(customers,
bulk => bulk.ColumnPrimaryKeyExpression = customer => customer.Code; });
var ctx = new EntitiesContext();
// Easy to use
ctx.BulkInsert(list);
// Easy to customize
context.BulkInsert(list, bulk => bulk.BatchSize = 100);
var ctx = new EntitiesContext();
ctx.Customers.AddRange(listToAdd);
ctx.Customers.RemoveRange(listToRemove);
listToModify.ForEach(x => x.DateModified = DateTime.Now);
// Easy to use
ctx.BulkSaveChanges();
// Easy to customize
<appSettings>
<add key="Z_EntityFramework_Extensions_LicenseName" value="[licenseName]"/>
<add key="Z_EntityFramework_Extensions_LicenseKey" value="[licenseKey]"/>
</appSettings>