Solved

How to bulk update using LINQ?

Posted on 2010-09-15
4
501 Views
Last Modified: 2012-05-10
I have a scenario where I need to update multiple records, preferably using LINQ.  For example, I need to update a list of SSRS reports that a user can view.  I  have a many-to-many junction table setup, iw_UserSSRSReport, in the database between the iw_SSRSReport and aspnet_Membership tables (see attached screenshot).

How would I insert/update the records in the junction table?  I am still in the planning stage so I haven't written any code, but I foresee an issue running into this.  

Do I need to add the User Id and SSRSReport ID to a collection and pass that to a method as a parameter, and then loop through the collection and inserting the items individually, and then calling SubmitChanges()?

And how would I update?  Would I have to first clear out the junction table where that user id exists, and then execute the same insert method?
ssrs-screenshot.png
0
Comment
Question by:markerasmus
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:existenz2
ID: 33689210
Are you using LINQ to Entities or LINQ to SQL? Then it shouldn't be a problem.
0
 

Author Comment

by:markerasmus
ID: 33689575
Linq to SQL.
0
 

Author Comment

by:markerasmus
ID: 33689676
Can you recommend an approach?
0
 
LVL 14

Accepted Solution

by:
existenz2 earned 500 total points
ID: 33699077
You probably have a parent child relation, so when you update the parent record you can configure that it also updates all the child records.Check http://blogs.msdn.com/b/charlie/archive/2007/02/20/one-to-many-and-joins.aspx for example.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now