Working with DAL directly
The logic layer is built on DAL's own Save and Delete
methods and nothing stops you from calling DAL directly for scripts, one-off
tooling or anywhere a full logic class is not worth setting up.
dal.Save(customer);
await dal.SaveAsync(customer);
dal.Delete(customer);
await dal.DeleteAsync(customer);
Both accept deep (default true), which cascades to related child
objects in the correct foreign key order and refreshModel (default
true), which reads database-assigned values, a generated identity, for example,
back onto the object after saving.
Batches
dal.SaveSet<Customer>(customers);
await dal.SaveSetAsync<Customer>(customers);
dal.DeleteSet<Customer>(customers);
await dal.DeleteSetAsync<Customer>(customers);
SaveSet and DeleteSet apply the same existence check, deep-save and
refresh behavior as Save and Delete, once per item, inside a single
transaction by default.
When every record is guaranteed to be new, after a table truncate or a bulk import, for example,
SaveBatchAsync skips the existence check, child saves and model refresh that
SaveSetAsync performs per item and is significantly faster for that specific case.
It does not support child objects or model refresh.
await dal.SaveBatchAsync<Customer>(newCustomers);
Transactions
Every save and delete method accepts globalTransaction, true by
default. With it on, the object, its child objects and any model refresh all run inside one
transaction, so a failure partway through rolls back everything, not just the last statement.
Set it to false when you are managing transaction scope yourself around multiple
separate calls.