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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:51:08+00:00 2026-05-17T16:51:08+00:00

net MVC Web Application. I have a database where i have made my model,

  • 0

net MVC Web Application. I have a database where i have made my model, i use Linq2SQL to build my Business Logic Layer. In my application i have a customer object, when i call my “editCystomer” page i pass in a Customer to populate the textBoxes:

[AcceptVerbs(HttpVerbs.Get)]
        [Authorize]
        public ViewResult EditCustomer(string id)
        {
            int customerId = Convert.ToInt32(id);
            CustomerRepository repository = new CustomerRepository();
            return View(repository.Load(customerId));
        }

When the user has changed in the textboxes i save my changed customer like this:

AcceptVerbs(HttpVerbs.Post)]
        [Authorize]
        public ActionResult EditCustomer(Customer customer)
        {         
            ValidateCustomer(customer);
            if (ModelState.IsValid)
            {
                CustomerRepository repository = new CustomerRepository();
                repository.Save(customer);
                return RedirectToAction("CreateCustomerDone");
            }
            else
            {
                return View();
            }
        }

Nothing fancy or unexpected so far, however in my save method:

public void Save(Customer customer)
        {
            if (customer.Id > 0)
                sdc.Refresh(System.Data.Linq.RefreshMode.KeepChanges, customer);
            else
                sdc.Customers.InsertOnSubmit(customer);

            sdc.SubmitChanges();
        }

…im getting an exception in my save (the update) that it cannot refresh the object (An object specified for refresh is not recognized. ). I have done this a million times before in other setups, how come its failing now? Any ideas?

  • 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-17T16:51:08+00:00Added an answer on May 17, 2026 at 4:51 pm

    The customer object you’re sending to Save() is not part of the DataContext. You need to either get the object again, then call the Refresh().

    Or you can do the following:

    public void Save(Customer customer)
    {
        if (customer.Id > 0)
        {
            Customer orig = sdc.Customers.GetOriginalEntityState(customer);
    
           if(orig == null)
                sdc.Attach(customer);
    
            sdc.Refresh(System.Data.Linq.RefreshMode.KeepChanges, customer);
        }
        else
            sdc.Customers.InsertOnSubmit(customer);
    
        sdc.SubmitChanges();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My new ASP.NET MVC Web Application works on my development workstation, but does not
I am trying to publish an Asp.net MVC web application locally using the NAnt
Other than the fact that ASP.NET MVC Web Application has more clarity in its
I'm trying to connect my stock standard, default ASP.NET MVC (web) application to the
I'm am building my asp.net web application using MVC (Preview 5), and am also
I have a Silverlight project (with ASP.net MVC web project) Suddenly, when I press
Background I have a page on my ASP.NET MVC web app for users to
Thanks to ASP.NET MVC framework, it became possible to unit test web applications. But
I am working on an ASP.NET MVC web app that allows people to publish
I need to provide a window on an ASP.NET MVC web page where registered

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.