我对Entity Framework有一段有趣的经历。我创建了一个接口和具体类,它实现了访问服务器上数据库的接口。我无意中使用了数据库中不存在的表名。在该问题上,而不是踢回关于数据库中不存在的表的错误,它已经在数据库中创建了表。
接口代码:
Task<List<Employees>> GetEmployeesAsync();
Task<Employees> GetEmployeesAsync(Guid Id);
Task<Employees> AddEmployeesAsync(Employees employee);
Task<Employees> UpdateCustomerAsync(Employees employee);
Task DeleteCustomerAsync(Guid employeeId);
具体代码:
public Task<List<Employees>> GetEmployeesAsync()
{
return _context.TblEmployees.ToListAsync();
}
public Task<Employees> GetEmployeesAsync(Guid Id)
{
return _context.TblEmployees.FirstOrDefaultAsync(e => e.Id == Id);
}
public async Task<Employees> UpdateCustomerAsync(Employees employee)
{
if (!_context.TblEmployees.Local.Any(e => e.Id == employee.Id))
{
_context.TblEmployees.Attach(employee);
}
_context.Entry(employee).State = EntityState.Modified;
await _context.SaveChangesAsync();
return employee;
}
有没有其他人经历过这个,有没有人对此有任何建议,这个问题是否可以解决?