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 8293333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:47:22+00:00 2026-06-08T13:47:22+00:00

I am accessing a database using LINQ, and making changes to the records. I

  • 0

I am accessing a database using LINQ, and making changes to the records. I retrieve the records like so:

using(var db = new DatabaseDataContext(connectionString))
{
    var query =
        from item in db.table
        where item.senddate == null
        select item;

    results = query.ToList();
}

After getting the items, I process each one, which requires communication with a web service, and can take more than a minute per record. When the record has been updated, I need to submit the changes, but I am not sure how to proceed. Currently, I do the following:

List<table> toProcess = QueryDb();  // Calls the previously displayed method

foreach (table item in toProcess)
{
     item.result = QueryDb(item.xmlrequest);
     PostToDb(item);
}

…

private bool PostToDb(table submit)
{
    submit.senddate = DateTime.Now;

    using (var db = new DatabaseDbDataContext(connectionString))
    {
        db.SubmitChanges();
    }

    return result;
}

db.SubmitChanges() does not submit any changes, but I haven’t really set that the object “submit” holds the changes. How do I submit the changes made to the entry without keeping the Db connection open for several minutes while the files are processed one at a time?

Thank you in advance for any assistance.

PARTIALLY RESOLVED

I don’t think this is the best solution, but I was able to get it to work with the following changes to my code:

private bool PostToDb(table submit)
{
    using (var db = new DatabaseDataContext(connectionString))
    {
        var query =
            from item in db.table
            where item.iprimaryid.Equals(submit.iprimaryid)
            select item;

        //  There can only be one result, but this was the only 
        //  way I could think to access it
        foreach (var item in query)
        {
            item.senddate = DateTime.Now;
            item.result = submit.result;
        }

        db.SubmitChanges();
    }

    return result;
}
  • 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-06-08T13:47:25+00:00Added an answer on June 8, 2026 at 1:47 pm

    You need to use the Attach method for your DataContext. So, your steps are:

    1) Query object from the database using one instance of your DataContext
    2) Make some changes
    3) Create the new DataContext instance and attach modified entities.

    using (var dataContext = new DataContext(ConnectionString))
    {
         dataContext.TABLE_NAME.Attach(modifiedEntity);
         dataContext.SubmitChanges();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using System.Data.Linq.DataContext file for accessing a mdf Database I want to use the
I'm in VS2008 with Entity Framework. I'm accessing objects from the database using esql
I'm accessing public mySQL database using JDBC and mySQL java connector . exonCount is
I'm using a MySQL database and accessing it through Java. PreparedStatement prep1 = this.connection.prepareStatement(
I'm accessing a database in steps, and making sure that I dispose of all
i'm having problems with accessing my database from my server. i'm newbie in FT,
What are the advantages of using an ESB instead of directly accessing a database
I'm accessing a data context object that is auto-generated by using LINQ to SQL.
i am making wcf rest service using linq. i wanna use stored procedure to
I have been looking at the various methods for accessing a database from silverlight

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.