Entity framework 3.5 and 4.0 offers even called SavingChanges. Entity framework 4.0 and 4.1 has a SaveChangesvirtual method (as already mentioned).
You can either override the method, or use an event handler, and write code like this for 3.5 and 4.0:
var entities = context.ObjectStateManager
.GetObjectStateEntries(EntitiState.Modified | EntityState.Added)
.Where(e => !e.IsRelationship)
.Select(e => e.Entity)
.OfType<YourEntityType>();
foreach(var entity in entities)
{
entity.Validate();
}
In the DbContext API (EF 4.1) you should use
var entities = context.ChangeTracker
.Entries<YourEntityType>()
.Where(e.State == EntityState.Added || e.State == EntityState.Modified)
.Select(e => e.Entity);
foreach(var entity in entities)
{
entity.Validate();
}
, , Validate.