markerasmus
asked on
How to bulk update using LINQ?
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
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
Are you using LINQ to Entities or LINQ to SQL? Then it shouldn't be a problem.
ASKER
Linq to SQL.
ASKER
Can you recommend an approach?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.