 |
| 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
|
|
|
|

August 11th, 2013, 02:20 PM
|
|
Authorized User
|
|
Join Date: Aug 2012
Posts: 39
Thanks: 4
Thanked 1 Time in 1 Post
|
|
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
|
|

August 11th, 2013, 03:07 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Did my previous answer about using TransactionScope not help? What is it you're not understanding from that solution?
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

August 11th, 2013, 08:45 PM
|
|
Authorized User
|
|
Join Date: Aug 2012
Posts: 39
Thanks: 4
Thanked 1 Time in 1 Post
|
|
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
|
|

August 15th, 2013, 09:39 PM
|
|
Authorized User
|
|
Join Date: Aug 2012
Posts: 39
Thanks: 4
Thanked 1 Time in 1 Post
|
|
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
|
|

August 16th, 2013, 02:48 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
>> 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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

August 19th, 2013, 09:42 PM
|
|
Authorized User
|
|
Join Date: Aug 2012
Posts: 39
Thanks: 4
Thanked 1 Time in 1 Post
|
|
Good explanation
Okay because it didn't "feel" right, so Yes, that makes sense. Thanks for the insightful reply.
|
|
 |