TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rupesh Kahane
102
19.1k
4.2m
How to use Begin Tran,Commit Rollback in Repository pattern
Dec 21 2016 11:58 PM
I have created a project using MVC Unit Of Work Repository Pattern.
I have implemented CRUD operation using repository pattern.
I have total 4 tables like 1) Master Table, 2) to 4) Detail Table.
Now I have a bellow situation I filled all text box on above form & click on save button. By using repository I am going to Insert data one by one i.e will store data into Master Details then Details 1 to Details 4.
But after inserting data into first 2 tables, because of some wrong information tables 3 & 4 are not inserted. So in this situation I would like to revert data from Master details and Details Table 1.
How can I use Begin Transaction, commit, rollback using repository pattern.
Bellow is my code
// Insert Data for Master Details table 1
MasterDetails objMaster=
new
MasterDetails();
objMaster.RFQ = UserTextValue;
objMaster.CompanyCode = UserTextValue;
//other fields
UnitoffWork.MasterDetailsRepository.Insert(objMaster);
UnitoffWork.MasterDetailsRepository.Save();
// Insert Data for Details 2
Details1 objD1=
new
Details1();
objD1.RFQDate = UserTextValue;
objD1.Item = UserTextValue;
//other fields
UnitoffWork.DetailsOneRepository.Insert(objD1);
UnitoffWork.DetailsOneRepository.Save();
// Insert Data for Details 3
Details2 objD2=
new
Details2();
objD2.TargVal = UserTextValue;
UnitoffWork.DetailsTwoRepository.Insert(objD2);
UnitoffWork.DetailsTwoRepository.Save();
// Insert Data for Details 4
Details3 objD3=
new
Details3();
objD3.YourReference = UserTextValue;
//other fields
UnitoffWork.DetailsThreeRepository.Insert(objD3);
UnitoffWork.DetailsThreeRepository.Save();
Thanks
Reply
Answers (
1
)
asp.net core mvc image resize when uploading
Asp.net session fundamental