I want to delete all the information with the entered TC from the database, but I cannot. I can do the same for Id and delete it. How can I do this? I take the this fault;
System.Data.Entity.Infrastructure.DbUpdateConcurrencyException: 'Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.'
OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information
public class EfEntityRepositoryBase<TEntity, TContext> : IEntityRepository<TEntity>
where TEntity : class, IEntity, new()
where TContext : DbContext, new()
{
public void Delete(TEntity entity)
{
using (TContext context = new TContext())
{
var deletedEntity = context.Entry(entity);
deletedEntity.State = EntityState.Deleted;
context.SaveChanges();
}
}
}
public interface IEntityRepository<T> where T : class, IEntity, new()
{
void Delete(T entity);
}
public interface IManagerPanelInformationDal :IEntityRepository<ManagerPanelInformation>
{
}
public class EfManagerPanelInformationDal : EfEntityRepositoryBase<ManagerPanelInformation, ManagerPanelContext>, IManagerPanelInformationDal
{
}
public class ManagerPanelInformationManager : IManagerPanelInformationService
{
public IManagerPanelInformationDal _managerPanelInformationDal;
public ManagerPanelInformationManager()
{
}
public void Delete(ManagerPanelInformation managerPanelInformation)
{
_managerPanelInformationDal.Delete(managerPanelInformation);
}
}
public interface IManagerPanelInformationService
{
void Update(ManagerPanelInformation managerPanelInformation);
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
_iManagerPanelInformationService.Delete(new ManagerPanelInformation
{
TC = Convert.ToInt64(tbxTCCC.Text)
});
MessageBox.Show("Tüm kişilerin bilgileri silindi!");
}
else
{
if (dgwRules.CurrentRow != null)
{
try
{
_iManagerPanelInformationService.Delete(new ManagerPanelInformation
{
Id = Convert.ToInt32(dgwRules.CurrentRow.Cells[0].Value)
});
MessageBox.Show("Kişi bilgisi silindi!");
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
if (!String.IsNullOrEmpty(tbxTCCC.Text))
{
dgwRules.DataSource = _iManagerPanelInformationService.GetManagerPanelInformationByTC(Convert.ToInt64(tbxTCCC.Text));
}
}
}
public interface IEntity
{
}
public class ManagerPanelInformation : IEntity
{
public int Id { get; set; }
public long TC { get; set; }
public string Kurallar { get; set; }
}
public class ManagerPanelContext : DbContext
{
public DbSet<ManagerPanelInformation> ManagerPanelInformations { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer<ManagerPanelContext>(null);
base.OnModelCreating(modelBuilder);
}
}