此代码抛出异常
System.InvalidOperationException:找不到实体类型"List <..>".确保已将实体类型添加到模型中.
private static void Update<T>(DbContext context, ICollection<T> existing, ICollection<T> updated) // where T: class
{
context.RemoveRange(existing);
updated.ToList().ForEach(existing.Add);
}
Run Code Online (Sandbox Code Playgroud)
但是,如果添加类型约束,则where T: class不会引发异常.为什么是这样?我的印象是C#类型约束没有影响这样的运行时行为.两个版本编译都很好.