嗨我正在尝试为删除操作编写一个通用存储库,这是我的存储库
public class Repository<T> : IRepository<T> where T : class, IAggregateRoot
{
private readonly DbSet<T> _entitySet;
private readonly StatosContext _statosContext;
public Repository(StatosContext statosContext)
{
_statosContext = statosContext;
_entitySet = statosContext.Set<T>();
}
public void Add(T entity)
{
_entitySet.Add(entity);
}
public void Delete(T entity)
{
_entitySet.Remove(entity);
}
}
当我通过这样的服务方法调用 Delete
public void RemoveContact(ContactViewModel contactViewModel)
{
var categoryView = new ContactViewModel { ContactId = contactViewModel.ContactId };
var contact = categoryView.ConvertToContactModel();
_contactRepository.Delete(contact);
_contactRepository.SaveChanges();
}
它不起作用,因为它找不到实体我如何在 mt Generic 存储库中编写 Delete 方法?