Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public static bool Update<U>(U dContext, int iCurrentUserId)
  2. where U : DbContext
  3. {
  4. using (var tx = dContext.Database.BeginTransaction())
  5. {
  6. try
  7. {
  8. foreach (T tItem in dContext.Set<T>())
  9. {
  10. if (dContext.Entry(tItem).State != EntityState.Modified) continue;
  11. ModificationSet(tItem, iCurrentUserId);
  12. }
  13. dContext.SaveChanges();
  14. tx.Commit();
  15. return true;
  16. }
  17. catch (Exception e)
  18. {
  19. tx.Rollback();
  20. return false;
  21. }
  22. }
  23. }
  24.  
  25. foreach (T tItem in dContext.Set<T>().Where(z => dContext.Entry(z).State == EntityState.Modified))
  26.  
  27. foreach (T tItem in dContext.ChangeTracker.Entries<T>().Where(z => z.State == EntityState.Modified).Select(z => z.Entity))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement