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
Solved

How to bulk update using LINQ?

Posted on 2010-09-15
4
505 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

840 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