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

You are currently viewing the ASP.NET 4 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 March 1st, 2012, 01:42 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
if I am not wrong then won't it hit database multiple times?
Yes, but in the end you need to do that anyway as you can't update multiple, unrelated rows. The suggestion from irProject with a WHERE clause is the only way really.

EF lets you update multiple rows. You query the objects you want to change, set properties on them and then update the changes.

Try a Google search for asp.net update multiple rows. You'll find lots of useful examples.

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!
 
Old March 1st, 2012, 02:37 PM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Ok I will use Stored procedures.

Quote:
EF lets you update multiple rows
curious, please give a code snippet how it updates multiple rows.

Many thanks both of you
 
Old March 1st, 2012, 02:45 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

EF does batch uodate by design. So it automatically saves changes to all objects in the context that have been changed. E.g.:

Code:
 
var article1 = context.Articles.Where (a => a.Id == 1).FirstOrDefault();
article1.SomeProperty = "SomeValue";
var article2 = context.Articles.Where (a => a.Id == 1).FirstOrDefault();
article2.SomeProperty = "SomeValue";
context.SaveChanges();
would save both articles.

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!
 
Old March 2nd, 2012, 12:40 PM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Thanks Imar,
it is working, and sooner I will use stored procesures

Thanks once again





Similar Threads
Thread Thread Starter Forum Replies Last Post
update multiple columns in an update statement debbiecoates SQL Server 2000 1 August 17th, 2008 04:01 AM
update rows with vbscript in asp sanjeev jha Classic ASP Professional 1 November 12th, 2007 03:24 AM
Highlighting multiple rows nzhang ASP.NET 2.0 Basics 1 June 21st, 2006 11:12 PM
print multiple times..multiple rows... abhit_kumar JSP Basics 3 January 18th, 2005 07:11 PM
Updating multiple Rows from multiple fields in ASP vdm_nana SQL Server ASP 0 April 1st, 2004 04:26 AM





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