我有這個模型在C#:我如何解決不能隱式轉換類型System.Collections.Generic.List?
public class interfaceModel
{
public string interfacename { get; set; }
public long id { get; set; }
}
和編寫代碼:
public static List<interfaceModel> CompanyInterfaceFetch()
{
var database = new DataBaseDataContext();
var companyinterface = new CompanyInterface();
var interfacelist =
database.CompanyInterfaces.Select(x => new interfaceModel { interfacename = x.InterfaceName, id=x.id});
return interfacelist.ToList();
}
// database model
public class interfaceModel
{
public string interfacename { get; set; }
public long id { get; set; }
}
現在我寫的代碼調用該方法:
public static List<interfaceModel> interfacefetch()
{
return Database.CompanyInterfaceFetch();
}
,但在這條線:
return Database.CompanyInterfaceFetch();
我得到這個錯誤:
Error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List
我該如何解決這個問題?謝謝。
你有兩個'interfaceModel'嗎? –
@ DanielA.White沒有隻有一個interfaceModel –
編譯器說你有2 –