Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public int PersistEntity(T entity)
  2. {
  3. var newRecords = 0;
  4. using (var context = new myEntities())
  5. {
  6. using (var dbcontext = context.Database.BeginTransaction())
  7. {
  8. var entity = new tblEntity();
  9. // ...
  10. context.tblEntities.Add(entity);
  11. //context.tblEntities.Attach(entity); // also tried this without success.
  12.  
  13. try
  14. {
  15. newRecords = context.SaveChanges();
  16. dbcontext.Commit();
  17. }
  18. catch (DbUpdateException)
  19. {
  20. throw; // thrown on context.SaveChanges()
  21. }
  22. }
  23. }
  24. return newRecords;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement