Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > ASP.NET 4.5 General Discussion
|
ASP.NET 4.5 General Discussion For ASP.NET 4.5 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4.5 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 11th, 2013, 02:20 PM
Authorized User
 
Join Date: Aug 2012
Posts: 39
Thanks: 4
Thanked 1 Time in 1 Post
Default Entity Framwork Transaction (committ/rollback)

Hello everyone,

I did a search on the forums in Beginning ASP and Professional ASP regarding the ability to use transactions to encapsulate multiple CRUD statements to be executed together or not at all. But it turned up no results.

So here goes:
Using a simple example, suppose I needed to do an insert into two related tables at once within a relational SQL Server database (e.g. 2012). And suppose I wanted to do it in Linq to Entities instead of a stored procedure. Can it be done? If so, is it as reliable as using a transaction block within a stored procedure? Are there any performance or quality issues with doing it that way?

Thanks!

Keywords (for anyone who does a similar search on this concept):
Entity Framwork Transaction
SQL Server Transaction in LINQ to Entities
Multiple inserts rollback in LINQ
 
Old August 11th, 2013, 03:07 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Did my previous answer about using TransactionScope not help? What is it you're not understanding from that solution?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
WebDev123 (August 11th, 2013)
 
Old August 11th, 2013, 08:45 PM
Authorized User
 
Join Date: Aug 2012
Posts: 39
Thanks: 4
Thanked 1 Time in 1 Post
Default

Oh, not at all, I just wanted to start some discussion on the topic. At this point, it seems like the Entity Framework has all but eliminated the need for stored procedures (unless of course you plan on manually editing the database).

But for anyone asking the same question... Stored Procedures in SQL Server vs. Entity Framework methods?, this could be an interesting thread. For example, when would using one over the other be considered a best practice? Are there any performance, reliability or maintenence issues with strictly using the framework in place of stored procedures when it comes to executing multiple SQL statements together (or concurrently).

It would be nice to get the opinions and feedback from those who already have had experience in this regard.

I figure I'll have more questions and comments on this as I continue along with my work.

Thanks.
WebDev
 
Old August 15th, 2013, 09:39 PM
Authorized User
 
Join Date: Aug 2012
Posts: 39
Thanks: 4
Thanked 1 Time in 1 Post
Default Intentional processing delays for Stored Procedures or Entity Framework?

Hello all !

Does this make sense ... ?

I put in a half second delay in my code behind, after each call to a stored procedure. I did this in order to ensure the database has enough time to process the transaction before I turn around on the next line of code and reference that information in a query or view.

I thought this was prudent, but I don't know if it is necessary? Is this a good practice? Is the answer the same if I'm using the Entity Framework to call a stored procedure?

Thanks!
WebDev
 
Old August 16th, 2013, 02:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> Does this make sense ... ?

Probably not. Depending on the actual code you have written, the call is most likely executed synchronously. That means the data is done, and the data is available as soon as the code is done running. No need for a delay.

However, it depends on your code. You could have "async code" which is non-blocking. However, in that scenario, waiting for "half a second" doesn't make sense. You should respond to the code "when it's done", which could be a millisecond later, or a minute. Async code makes it easy to do that.

My guess is that you're not writing async code in which case a delay is not necessary. Post your code and we can tell for sure.

Cheers,


Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
WebDev123 (August 19th, 2013)
 
Old August 19th, 2013, 09:42 PM
Authorized User
 
Join Date: Aug 2012
Posts: 39
Thanks: 4
Thanked 1 Time in 1 Post
Default Good explanation

Okay because it didn't "feel" right, so Yes, that makes sense. Thanks for the insightful reply.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Entity Framwork Transaction (committ/rollback) WebDev123 BOOK: Beginning ASP.NET 4.5 : in C# and VB 1 August 11th, 2013 06:14 AM
Rollback of Delete gaurav_jain2403 SQL Server 2000 2 August 3rd, 2006 01:32 AM
Difference between Entity and Entity type arshad mahmood C++ Programming 0 May 8th, 2004 12:34 AM
How do I Avoid a ROLLBACK when... wmhhodson SQL Server 2000 1 October 31st, 2003 01:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.