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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:24:53+00:00 2026-06-17T11:24:53+00:00

Does Entity Framework incorrectly detect changes to images? I have a Person entity class

  • 0

Does Entity Framework incorrectly detect changes to images?

I have a “Person” entity class defined as follows;

public class Person
{
 public int Id { get; set; }
 public byte[] Photo { get; set; }
}

I have bound the Photo to a PictureBox control on my form using a datasource.
There form also uses a dynamically created bindingNavigator.

I also have written an audit log to populate captured changes
The procedure calls the ObjectContext DetectChanges() and then

var entries = ObjectContext.ObjectStateManager.GetObjectStateEntries()    

Which contains an entry showing that the Photo has been modified.
entry.OriginalValues[name] matches entry.CurrentValues[name]

The Column is varbinary(MAX) in SQL Server and the size of the picture files I have loaded are under 1Mb

If I set all of the columns to null the error no longer occurs

The code I use to get the file is

private void LoadPhotoButton_Click(object sender, EventArgs e)
{
   using (var dlg = new OpenFileDialog())
  {
      dlg.Filter = "JPEG files |*.jpg";
      if (dlg.ShowDialog() == DialogResult.OK)
      {
          PhotoPictureBox.Image = Image.FromFile(dlg.FileName);
      }
   }
 }

I note here that hex zero can be inserted as padding characters when these fields are involved in string conversion…. could the binding be doing that somehow?

If I delete the picturebox from the form, or even bind the control as a text box instead of a picturebox then the behaviour is correct ( not that a picture bound to a text box is any use )

I am able to work around the problem by not binding directly to the picture box.
Instead I just load it on the BindingSource_CurrentChanged event using

private void BindingSource_CurrentChanged(object sender, EventArgs e)
    {
        var obj = (Person) BindingSource.Current;
        this.PictureBox.Image = byteArrayToImage( obj.Photo);
    }

public Image byteArrayToImage(byte[] byteArrayIn)
    {
        MemoryStream ms = new MemoryStream(byteArrayIn);
        Image returnImage = Image.FromStream(ms);
        return returnImage;
    }
  • 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-17T11:24:53+00:00Added an answer on June 17, 2026 at 11:24 am

    I am using my work around – documented at the end of the question as a make do answer.

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

Sidebar

Related Questions

Using Entity Framework Code First, I have something like: public class Foo { public
Someone has an answer to this missing feature in Entity Framework. Does anyone have
I running schema update for Symfony2 gives: Warning: class_parents(): Class Tg\UserBunde\Entity\Person does not exist
Why does entity framework pluralize all the class names and capitalize the first letters
Does the entity framework 4.0 track changes on Plain old C# object? If so,
Does ADO.NET Entity Framework have a construct similar to LINQ to SQL's GetTable? I'm
Does the Entity Framework 4 have ordered collections? For example my Order has a
Let's say we have the following simple model: public class Car { public int
Why does the Entity Framework generate nested SQL queries? I have this code var
Currently I have class hierarchy defined with the Code First approach as follows. E.F.

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.