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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:41:43+00:00 2026-05-13T13:41:43+00:00

I recently worked through Steve Sanderson’s Pro ASP.NET MVC Framework and ran into an

  • 0

I recently worked through Steve Sanderson’s Pro ASP.NET MVC Framework and ran into an issue with the sample “SportsStore” application. SportsStore is a simple CRUD app that provides an editor to insert and update products in the store. Each product can have an image (which is stored in a SQL Server database, I know, maybe not the best idea but that’s a debate for another thread).

The issue that I noticed is that when you update a product, if the product has an image, you lose the product image. This is happening because the code doing the updating is looking for fields that have changed compared to what’s currently in the database. When the DataContext sees that the file upload dialog from the product update form is empty, it sets the ImageData and ImageMimeType fields to null. What I’m hoping to do is tell the DataContext not touch the ImageData and ImageMimeType fields if you’re doing an update and the file upload dialog content is empty. Here’s the current code that writes changes to the database:

public void SaveProduct(Product product)
{
    EnsureValid(product, "Name", "Description", "Category", "Price");

    // If it's a new product, just attach it to the DataContext
    if (product.ProductID == 0)
        productsTable.InsertOnSubmit(product);
    else {
        // If we're updating an existing product, tell the DataContext
        // to be responsible for saving this instance
        productsTable.Attach(product);
        // Also tell the DataContext to detect any changes since the last save
        productsTable.Context.Refresh(RefreshMode.KeepCurrentValues, product);
    }

    productsTable.Context.SubmitChanges();
}

If I need to post more, just let me know. You can download all the source code for this app from the book’s site. The app is in the “Chapter 04 to 06 – SportsStore” directory.

Being an ASP.NET MVC noob, I’m not sure if my idea of trying to tell the DataContext to not update specific fields is correct. If anyone else has a better plan, I’m open to ideas. The goal is to preserve the image in the database on updates.

  • 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-13T13:41:43+00:00Added an answer on May 13, 2026 at 1:41 pm

    Maybe this is the opposite of my problem here; try changing the key line to:

    memberCache.Set(metaMember.Ordinal, false);
    

    You should be able to use this by overriding SubmitChanges in your data-context:

    public override void SubmitChanges(ConflictMode failureMode)
    {
        foreach(object obj in GetChangeSet().Updates) {
            // toggle
        }
        base.SubmitChanges(failureMode);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently reached the stage where an ASP.net MVC application I am developing is
Recently I have applied for a job through the agency. She emailed me with
I have a curious problem: My app is distributed through ClickOnce. I recently installed
I recently had this issue with a client. The code read: ini_set( sendmail_from, noreply@<current-domain>.com
I've just recently moved a lot of my Views and Controllers into more appropriate
Recently I've been working on a C++ prime generator that uses the Sieve of
I recently read a post on The Anemic Domain Model Pattern which caught my
I was working on some code recently and came across a method that had
I recently wrote a theme function to add a class to my primary links

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.