0

One column named Favorite(tinyint) in table of "Products" in sql server. I have generated entity it is converted into entity as looking like,

public class Products
{
   ----- Other Fields ------
    public byte Favorite { get; set; }
}

I am trying to update entity as by given code below,

 using (ADataContext dataContext = new ADataContext())
 {

     var product = dataContext.Products.Where(p => p.Id == 10).FirstOrDefault();
     product.Favorite = (byte)EnumFavoriteType.MostFavorite;
     dataContext.SubmitChanges();
 }

It is not updating and showing error

"An exception of type 'System.Data.Linq.ChangeConflictException' occurred in 'A.Service.dll but was not handled in user code". "Row not found or changed."

FLICKER
  • 6,439
  • 4
  • 45
  • 75
Vimal Dhaduk
  • 994
  • 2
  • 18
  • 43

1 Answers1

0

I change entity class and added PropertyChanged of Favorite Property by following,

public class Products
{

  public byte Favorite { get; set; }
        {
            get
            {
                return this.Favorite;
            }
            set
            {
                if ((this.Favorite != value))
                {

                    this.OnFavoriteChanging(value);
                    this.SendPropertyChanged("Favorite");
                }
            }
        }

    partial void OnFavoriteChanging(byte value);

    protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
}

It works fine for me.

Vimal Dhaduk
  • 994
  • 2
  • 18
  • 43