I'm trying to develop a simple c# MVVM CRUD application which hooks up to a SQL Server database, I'm currently having an issue deleting records of my entities Apparently the entityId I'm searching for returns null, in which I'm pretty much sure it exists in the database, Therefore no deleting happens I could really use you help! thank you!
public async Task<bool> Delete(int id)
{
using (MyDbContext context = _contextFactory.CreateDbContext())
{
T entity = await context.Set<T>().FirstOrDefaultAsync((e) => e.Id == id);
context.Set<T>().Remove(entity);
context.SaveChangesAsync();
return true;
}
}
1条答案
按热度按时间xggvc2p61#
Well I'm not getting any error, this is the code I'm running for deleting a user with
Id = 2
: