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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:25:18+00:00 2026-05-10T20:25:18+00:00

I am using asp.net mvc for an application. I’ve taken some guidance from Rob

  • 0

I am using asp.net mvc for an application. I’ve taken some guidance from Rob Conery’s series on the MVC storefront. I am using a very similar data access pattern to the one that he used in the storefront.

However, I have added a small difference to the pattern. Each class I have created in my model has a property called IsNew. The intention on this is to allow me to specify whether I should be inserting or updating in the database.

Here’s some code:

In my controller:

OrderService orderService = new OrderService(); Order dbOrder = orderService.GetOrder(ID);  if (ModelState.IsValid) {     dbOrder.SomeField1 = 'Whatever1';     dbOrder.SomeField2 = 'Whatever2';     dbOrder.DateModified = DateTime.Now;     dbOrder.IsNew = false;      orderService.SaveOrder(dbOrder); } 

And then in the SQLOrderRepository:

public void SaveOrder(Order order) {     ORDER dbOrder = new ORDER();      dbOrder.O_ID = order.ID;     dbOrder.O_SomeField1 = order.SomeField1;     dbOrder.O_SomeField2 = order.SomeField2;     dbOrder.O_DateCreated = order.DateCreated;     dbOrder.O_DateModified = order.DateModified;      if (order.IsNew)         db.ORDERs.InsertOnSubmit(dbOrder);      db.SubmitChanges(); } 

If I change the controller code so that the dbOrder.IsNew = true; then the code works, and the values are inserted correctly.

However, if I set the dbOrder.IsNew = false; then nothing happens…there are no errors – it just doesn’t update the order.

I am using DebuggerWriter here: http://www.u2u.info/Blogs/Kris/Lists/Posts/Post.aspx?ID=11 to trace the SQL that is being generated, and as expected, when the IsNew value is true, the Insert SQL is generated and executed properly. However, when IsNew is set to false, there appears to be no SQL generated, so nothing is executed.

I’ve verified that the issue here (LINQ not updating on .SubmitChanges()) is not the problem.

Any help is appreciated.

  • 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. 2026-05-10T20:25:19+00:00Added an answer on May 10, 2026 at 8:25 pm

    In your SaveOrder method you are always creating a new ORDER object. You need to change this so that if order.IsNew is false, it retrieves the existing one from the DB and updates it instead.

    public void SaveOrder(Order order) {     ORDER dbOrder;     if (order.IsNew)     {         dbOrder = new ORDER();         dbOrder.O_ID = order.ID;     }     else     {         dbOrder = (from o in db.ORDERS where o.O_ID == order.ID select o).Single();     }      dbOrder.O_SomeField1 = order.SomeField1;     dbOrder.O_SomeField2 = order.SomeField2;     dbOrder.O_DateCreated = order.DateCreated;     dbOrder.O_DateModified = order.DateModified;      if (order.IsNew)         db.ORDERs.InsertOnSubmit(dbOrder);      db.SubmitChanges(); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using asp.net MVC to develop an application that will have ajax interactions.
I am currently building an application using ASP.NET MVC. The data entry pages are
I'm using a few (2 or 3) master pages in my ASP.NET MVC application
I am trying to publish an Asp.net MVC web application locally using the NAnt
I'm using the MVC beta to write a simple application to understand ASP.Net MVC.
I'm am building my asp.net web application using MVC (Preview 5), and am also
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using asp.net MVC I'd like to do this inside a view: <%= Html.TextBox(textbox1, null,
I'm using ASP.NET MVC Preview 4 and would like to know how to use
I am attempting to pull some information from my tnsnames file using regex. I

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.