Can I disable update / deletion in EF First code?

Is it possible to create an EF object that allows you to create records, but disable update and deletion. I have a data object that I want to allow code to create records in the database, but they are not allowed to modify or delete them. I am using the first approach of EF code.

+6
source share
1 answer

Yes, you can override the SaveChanges method of your DbContext and you can prevent this.

 public override int SaveChanges() { foreach (DbEntityEntry entity in this.ChangeTracker.Entries) { if (entity.State == System.Data.EntityState.Modified) return; // more logic, depending on your needs } base.SaveChanges(); } 
+6
source

Source: https://habr.com/ru/post/906383/


All Articles