Click here to Skip to main content
15,885,985 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I dictate the position of the run prompt? Pin
Alan N29-Apr-14 11:25
Alan N29-Apr-14 11:25 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk330-Apr-14 6:11
turbosupramk330-Apr-14 6:11 
GeneralRe: How can I dictate the position of the run prompt? Pin
Alan N1-May-14 3:12
Alan N1-May-14 3:12 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk32-May-14 1:46
turbosupramk32-May-14 1:46 
QuestionImplementing transaction in MVC as Attribute Pin
nitin_ion28-Apr-14 0:12
nitin_ion28-Apr-14 0:12 
AnswerRe: Implementing transaction in MVC as Attribute Pin
Dave Kreskowiak28-Apr-14 3:18
mveDave Kreskowiak28-Apr-14 3:18 
GeneralRe: Implementing transaction in MVC as Attribute Pin
nitin_ion28-Apr-14 17:19
nitin_ion28-Apr-14 17:19 
GeneralRe: Implementing transaction in MVC as Attribute Pin
Dave Kreskowiak28-Apr-14 17:55
mveDave Kreskowiak28-Apr-14 17:55 
OK, that's still a bit backwards. The controller should be concerned with translating between the View (ViewModel) and the Business Logic, not controlling a transaction which is something that belongs in the Data Layer and possibly controlled by the Business Logic.

So long as the last call you make in the Business Logic is the DbContext.SaveChanges, all the changes the Business Logic makes will be wrapped in a Transaction AUTOMATICALLY. You don't have to create a transaction yourself!
public class BusinessLogic
{
    private MyDbContext context = new MyDbContext();

    public void BusinessFunction1()
    {
        // Don't call SaveChanges in here.
    }

    public void BusinessFunction2()
    {
        // Don't call SaveChanges in here.
    }

    public void SaveChanges()
    {
        // All changes made above will automatically be wrapped
        // in a transaction by EF.
        context.SaveChanges();
    }

    public void Dispose()
    {
        context.Dispose();
    }
}


Besides, you already linked to the article that shows you how to do it! I already linked to a couple of articles that shows you the pitfalls of what you want to do.

The problem with what you want to do is that you have to be VERY careful that the transaction mode you use doesn't LOCK THE ENTIRE TABLE while you do your transaction processing. If you're not careful, the lock will prevent other instances from even reading the data in locked tables, preventing other users of your web site from seeing pages that are backed by data!

QuestionHow to use Multithreading in Async Socket Http request Pin
sbmzhcn27-Apr-14 15:22
sbmzhcn27-Apr-14 15:22 
Questionlooking for a decent book on c# for advanced programmers Pin
Nico Haegens27-Apr-14 1:10
professionalNico Haegens27-Apr-14 1:10 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
Pete O'Hanlon27-Apr-14 1:59
mvePete O'Hanlon27-Apr-14 1:59 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
BillWoodruff27-Apr-14 7:08
professionalBillWoodruff27-Apr-14 7:08 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
jschell27-Apr-14 9:36
jschell27-Apr-14 9:36 
GeneralRe: looking for a decent book on c# for advanced programmers Pin
Ravi Bhavnani28-Apr-14 4:44
professionalRavi Bhavnani28-Apr-14 4:44 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
thatraja27-Apr-14 20:59
professionalthatraja27-Apr-14 20:59 
GeneralRe: looking for a decent book on c# for advanced programmers Pin
Dnyaneshwar@Pune28-Apr-14 0:11
Dnyaneshwar@Pune28-Apr-14 0:11 
GeneralRe: looking for a decent book on c# for advanced programmers Pin
rutja_deore28-Apr-14 0:12
rutja_deore28-Apr-14 0:12 
GeneralRe: looking for a decent book on c# for advanced programmers Pin
thatraja28-Apr-14 4:29
professionalthatraja28-Apr-14 4:29 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
Ravi Bhavnani28-Apr-14 4:43
professionalRavi Bhavnani28-Apr-14 4:43 
QuestionRunning thread to refresh image disable scrollbars in DataGridView Pin
neualex26-Apr-14 5:44
neualex26-Apr-14 5:44 
AnswerRe: Running thread to refresh image disable scrollbars in DataGridView Pin
OriginalGriff26-Apr-14 6:06
mveOriginalGriff26-Apr-14 6:06 
GeneralRe: Running thread to refresh image disable scrollbars in DataGridView Pin
neualex28-Apr-14 3:28
neualex28-Apr-14 3:28 
GeneralRe: Running thread to refresh image disable scrollbars in DataGridView Pin
OriginalGriff28-Apr-14 3:34
mveOriginalGriff28-Apr-14 3:34 
QuestionI got this error on page load my photo gallery page . http://s.codeproject.com/script/Forums/Images/smiley_WTF.gif Pin
300sparta25-Apr-14 23:03
300sparta25-Apr-14 23:03 
AnswerRe: I got this error on page load my photo gallery page . http://s.codeproject.com/script/Forums/Images/smiley_WTF.gif Pin
OriginalGriff25-Apr-14 23:18
mveOriginalGriff25-Apr-14 23:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.