Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6751637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:57:01+00:00 2026-05-26T12:57:01+00:00

Kind a simple problem, but i am completely lost on how to approach to

  • 0

Kind a simple problem, but i am completely lost on how to approach to this.

CREATE TABLE Contract (
  id int PRIMARY KEY,
  batchId int NOT NULL REFERENCES ContractBatch (id)
  campaignId int NULL REFERENCES Campaign (id)
)

This is simplified table in my business model, made to Linq2Sql model. Now i need to do update query like this:

UPDATE Contract SET campaignId = 1 WHERE batchId = 5

That means, there can be more records for same ContractBatch and i need to set Campaign for all of them. Is it possible to convert this query to Linq expression in some easy way ? Only way i am able find is fetch all those records for that ContractBatch and then update one by one in loop. That’s not very efficient.

var campaignId = 1;
var batchId = 5;
using( var dataContext = new DataModel.ModelDataContext() ) {
    dataContext.Contracts
        .Where( c => c.BatchId == batchId )
        // this is obviously my "wish to have" method
        .ForEach( c => c.CampaignId = campaignId )
    dataContext.SubmitChanges()
}

I am already thinking about doing it in old way and execute that query by hand. I don’t like it, but it’s probably better than running like hundreds of update queries.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:57:02+00:00Added an answer on May 26, 2026 at 12:57 pm

    You are right that there are two problems with this approach – you will be executing hundreds of individual update statements, and you have to read them in the first place to do the change.

    This is a common weakness in ORMs.

    Following a few google links I found the following blog post, which does have some interesting things to say in this area:
    http://www.aneyfamily.com/terryandann/post/2008/04/Batch-Updates-and-Deletes-with-LINQ-to-SQL.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I'm having a problem with a simple textarea. I'm using a kind
I feel kind of dumb posting this when this seems kind of simple and
This is kind of a simple question, however, I don't seem to figure out
I would like to make a simple desktop application to learn this kind of
I'm trying to do a simple update. I've done this kind of thing thousands
I am not sure the best approach to this problem, be it through reflection,
EDIT: Sometimes it happens that our problem is kind of not in code but
This is kind of an unusual problem. I am having difficulty encrypting a file
I'm new to OpenGL ES and having a simple kind of problem in my
Could anybody be so kind to give me a simple example of reification in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.