Store update, insert ou delete touchés inattendue . Les entités modifiée ou supprimée depuis entités ont été chargés

Je suis en utilisant MVC pour mon projet .

J'ai ajouté un contrôleur nommé group et dans ce contrôleur, j'ai un peu d'action, comme d'habitude, comme créer et modifier et etc .

mais mon problème se réfère à edit méthode Comme vous pouvez le voir ici :

public ActionResult Edit(int GroupId)
{
    ViewBag.groupIdLST = new SelectList(OBJgroupRepository.FindBy(i => i.GroupId == null).ToList(), "Id",
    ViewBag.GroupType = new SelectList(OBJgroupRepository.FindBy(i => i.GroupId == null).ToList(), "name",
    DomainClass.Group tg = OBJgroupRepository.FindBy(i => i.Id == GroupId).First();
    return View(tg);
}
[HttpPost]
public ActionResult Edit(Group gr)
{
    if (ModelState.IsValid)
    {
        OBJgroupRepository.Edit(gr);
        OBJgroupRepository.Save();
    }
    TempData["success"] = "اطلاعات با موفقیت ویرایش شد";
    return RedirectToAction("Create");
}

Quand je clique sur le bouton modifier, j'ai eu cette erreur :

Store update, insert ou delete touchés inattendue
nombre de lignes (0). Les entités peuvent avoir été modifiés ou supprimés depuis
les entités ont été chargés. Voir
http://go.microsoft.com/fwlink/?LinkId=472540 pour plus d'informations sur
la compréhension et la manipulation de l'accès concurrentiel optimiste exceptions.

Mon modifier et enregistrer méthode :

public virtual void Edit(T entity)
{
    _entities.Entry(entity).State = System.Data.Entity.EntityState.Modified;
}

public virtual void Save()
{
    try
    {
        _entities.SaveChanges();
    }
    catch (DbEntityValidationException e)
    {
        foreach (var eve in e.EntityValidationErrors)
        {
            Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                eve.Entry.Entity.GetType().Name, eve.Entry.State);
            foreach (var ve in eve.ValidationErrors)
            {
                Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                    ve.PropertyName, ve.ErrorMessage);
            }
        }
        throw;
    }
}

mon référentiel :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DomainClass;
using ProjectModel;

namespace Repository
{
    public class GroupRepository : GenericRepository<DataAccessModelContainer, Group>
    {
    }
}

Tous les détails sont disponibles sur demande.

Meilleures salutations .

InformationsquelleAutor Ehsan Akbar | 2015-02-01