Linq输出作为接口?

ken*_*one 4 linq casting interface

这是我试图做的代码:

public IList<IOperator> GetAll()
{
      using (var c = new MyDataContext())
      {
          return c.Operators.ToList();
      }
}
Run Code Online (Sandbox Code Playgroud)

运算符实现IOperator,但我收到以下编译错误:

Cannot implicitly convert type 'System.Collections.Generic.List<MyProject.Core.Operator>' to 'System.Collections.Generic.IList<MyProject.Core.Model.IOperator>'. An explicit conversion exists (are you missing a cast?)
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能得到我需要的东西?

Pan*_*nos 6

尝试Cast<>()方法:

return c.Operators.Cast<IOperator>().ToList();
Run Code Online (Sandbox Code Playgroud)