Solved

How to bulk update using LINQ?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tool Box 2 35
Run time Error 4 34
Executing SSIS with a Stored Procedure Permissions 12 26
What namespace do I need to import? 2 13
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

23 Experts available now in Live!

Get 1:1 Help Now