Allow validation/business rules
When using EntityDac, it would be great to be able to define business rules on entities (validations).
Those would be enforced by the framework when updating an entity. Perhaps they could be done in a single transaction.
In other words EntityDAC should be able to emulate the concepts of triggers and stored procedures with Linq.
I would also like to be able to do other operations when a model is saved :
TModel.OnSave = procedure(aModel : TModel; aTransaction : TTransaction);
if aModel.IsBlue then aTransaction.Rollback;
aModel.OtherEntity.MagicProp := 'Black';
aModel.Another.Blabla := 2;
Linq.From(TSupModel).Where(TSupModel.a = TSupModel.b).Update(TSupModel.c = TSupModel.d);
if AnotherCondition then
When Saving or updating entities, it is important to validate business rules. Those are invariants, and cannot be done in multiple transactions. If I want to save a TMyEntity, I have to check that it meets some conditions that maybe are related to data in the database. For now, it is impossible to do so with EntityDAC unless we use Stored Procedures. But, the ORM goal is to decouple the database from the application. And stored procedures go against this. We should be able to define "Application" procedures with Linq.
If I update MyModel, I have to check that AnotherModel condition is met. But now, with EntityDAC, it's not possible to do this in a single transaction. It introduces a risk of data corruption. I would like to be able to write :
TModel.Validate := procedure(aModel : TModel; var isValid : boolean) begin
// In a transaction
if aModel.isBlue then ...
if aModel.AnotherModel.AnotherProp ...
isValid := true;