Error trying to update with ASP.NET MVC5 entity framework


I have the following problem when I try to update the Gender object, it shows me the following error when I do the update, help

        Common.Entities.Gender gender = this.genderRepository.FindGenderId(genderModel.GenderId);

        Domain.Models.Gender myGender = new Domain.Models.Gender
            GenderId = gender.GenderId,
            GenderName = genderModel.GenderName,
            CreateBy = gender.CreateBy,
            CreationDate = gender.CreationDate,
            ModifiedBy = genderModel.ModifiedBy,
            ModifiedDate = genderModel.ModifiedDate,

        serviceResult.Data = "Genero modificado.";
    catch (Exception ex)
        serviceResult.Data = "Ocurrio un error modificado el genero.";

    return serviceResult;

and this is the objecto that I believe so that I update the data to make the update

public void UpdateGender(Models.Gender myGender)

    this.unitOfWorkModel.Repository<Gender>().Update(new Gender
        GenderId = myGender.GenderId,
        GenderName = myGender.GenderName,
        CreateBy = myGender.CreateBy,
        CreationDate = myGender.CreationDate,
        ModifiedBy = myGender.ModifiedBy,
        ModifiedDate = myGender.ModifiedDate,


This is the image, with the error.

asked by Ing. Jose Valera 04.01.2019 в 14:24

1 answer


One of the solutions is that you make the Select (Method to select the records) before the update. What you will achieve is that the registry is cached when it is found. You must add AsNoTracking() in the method you are using to select the data.

answered by 04.01.2019 в 14:51