Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to bulk update using LINQ?

Posted on 2010-09-15
4
Medium Priority
?
514 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

618 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