【发布时间】:2022-11-24 02:48:31
【问题描述】:
我尝试执行软删除时出错
无法将类型“System.Collections.Generic.List<##.##.Employee>”隐式转换为“Microsoft.AspNetCore.Mvc.IActionResult”。
这是我的索引,我尝试使用 ToList() 和 ToList 但它不起作用
public IActionResult Index()
{
var employees = _dbContext.Employees.Where(x => x.status == '1')
.ToList();
return employees;
}
我的数据库上下文
public class DataContext : DbContext
{
public DataContext(DbContextOptions options) : base(options)
{
}
public DbSet<Employee> Employees { get; set; }
public override int SaveChanges()
{
foreach( var entry in ChangeTracker.Entries())
{
var entity = entry.Entity;
if (entry.State == EntityState.Deleted)
{
entry.State = EntityState.Modified;
entity.GetType().GetProperty("status").SetValue(entity, '0');
}
}
return base.SaveChanges();
}
}
}
员工 命名空间 empAPI.Models { 公共课员工 {
public Guid Id { get; set; }
public char status{ get; set; } = '1';
public string Name { get; set; }
public string Department { get; set; }
public DateTime? CreatedDate { get; set; } = DateTime.Now;
} }
【问题讨论】:
标签: c# asp.net-mvc entity-framework