C# 无法将MyModel类型隐式转换为System.Collections.Generic.List<;T>;

C# 无法将MyModel类型隐式转换为System.Collections.Generic.List<;T>;,c#,generics,C#,Generics,我有一个模型课,如下所示 public class MyModel { [SQLite.PrimaryKey] public int Id { get; set; } public string Name { get; set; } public string Status { get; set; } } public interface IService { List<MyModel> IGetEmployeeDetails(); } 一个

我有一个模型课,如下所示

public class MyModel
{
    [SQLite.PrimaryKey]
    public int Id { get; set; }
    public string Name { get; set; }
    public string Status { get; set; }
}
public interface IService
{
   List<MyModel> IGetEmployeeDetails();
}
一个接口类,其中我有一个返回类型为MyModel类method的方法,如下所示

public class MyModel
{
    [SQLite.PrimaryKey]
    public int Id { get; set; }
    public string Name { get; set; }
    public string Status { get; set; }
}
public interface IService
{
   List<MyModel> IGetEmployeeDetails();
}
公共接口iSeries设备
{
列出IGetEmployeeDetails();
}
上述接口已在我的服务类中实现,如下所示:

public List<MyModel> IGetEmployeeDetails()
{
    return _connection.Table<MyModel>().ToList(); 
}
公共列表IGetEmployeeDetails()
{
返回_connection.Table().ToList();
}
上面的实现对我来说一切都很好,但是当我尝试将接口方法更改为泛型返回类型时,我面临接口方法的返回类型问题,如下所示

列表IGetEmployeeDetails()
列出IGetEmployeeDetails()我得到了

无法将类型
MyModel
隐式转换为
System.Collections.Generic.List

基本上,我想让我的接口方法返回类型为泛型,但我不确定如何在我的服务类中将结果从MyModel类型转换为泛型类型

仅供参考,我已经审理了以下案件

  • return\u connection.Table().ToList()
  • return(List)\u connection.Table().ToList()&等
任何帮助都要提前感谢

基本上我想让我的接口方法返回类型为泛型,但是 我不知道如何在我的服务类中从
MyModel
转换为泛型类型

您所寻找的是类级别的泛型,而不是您所尝试的函数级别的泛型

如果函数是泛型函数,则调用方指定一个
T
,函数必须处理它。在您的情况下,您需要不同的
iSeries设备
实现,每个实现都能够返回不同的集合。因此:

public interface IService<T>
{
   List<T> GetEmployeeDetails();
}
公共接口iSeries设备
{
列出GetEmployeeDetails();
}
以及导出的:

public class DerivedService : IService<MyModel>
{
    public List<MyModel> GetEmployeeDetails()
    {
        return _connection.Table<MyModel>().ToList(); 
    }
}
公共类派生服务:IService
{
公共列表GetEmployeeDetails()
{
返回_connection.Table().ToList();
}
}

非常感谢@Gilad Green,这就像一个符咒:)