Settings and activity
3 results found
-
25 votesAnonymous shared this idea ·
An error occurred while saving the comment An error occurred while saving the comment Anonymous commentedI would also like to be able to do other operations when a model is saved :
TModel.OnSave = procedure(aModel : TModel; aTransaction : TTransaction);
beginif 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
aTransaction.Commit;
else
aTransaction.Rollback;end;
An error occurred while saving the comment Anonymous commentedWhen 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;end;
-
10 votesAnonymous shared this idea ·
-
16 votesAnonymous shared this idea ·
In other words EntityDAC should be able to emulate the concepts of triggers and stored procedures with Linq.