Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int PersistEntity(T entity)
- {
- var newRecords = 0;
- using (var context = new myEntities())
- {
- using (var dbcontext = context.Database.BeginTransaction())
- {
- var entity = new tblEntity();
- // ...
- context.tblEntities.Add(entity);
- //context.tblEntities.Attach(entity); // also tried this without success.
- try
- {
- newRecords = context.SaveChanges();
- dbcontext.Commit();
- }
- catch (DbUpdateException)
- {
- throw; // thrown on context.SaveChanges()
- }
- }
- }
- return newRecords;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement