Guest User

Untitled

a guest
May 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public void UpdateEnt<T>(T entity) where T : parent_table
  2. {
  3. if (entity == null)
  4. {
  5. throw new ArgumentException("Cannot add a null entity.");
  6. }
  7. using (var _context = (DataModelDetach)d.GetContextForRead(Module))
  8. {
  9. var entry = _context.Entry<T>(entity);
  10.  
  11. if (entry.State == EntityState.Detached)
  12. {
  13. var set = _context.Set<T>();
  14. T attachedEntity = set.Include(x => x.children_1).Include(x => x.children_2).SingleOrDefault(e => e.idSeq == entity.idSeq);
  15.  
  16.  
  17. if (attachedEntity != null)
  18. {
  19. var attachedEntry = _context.Entry(attachedEntity);
  20. attachedEntry.CurrentValues.SetValues(entity);
  21. }
  22. else
  23. {
  24. entry.State = EntityState.Modified; // This should attach entity
  25. }
  26.  
  27.  
  28.  
  29. }
  30.  
  31. }
  32. }
Add Comment
Please, Sign In to add comment