我是新来的LINQ 我收到此错误无法隐式转换类型“System.Collections.Generic.List <AnonymousType#1>”到“System.Collections.Generic.List
无法隐式转换键入
System.Collections.Generic.List<AnonymousType#1>
到System.Collections.Generic.List<DirCert.Data.Model.DssClient_Sasid_Certified>
我无法弄清楚如何解决这个错误。
这里是我的代码:
public List<DssClient_Sasid_Certified> GetCertifiedRecordsbySasid(string Sasid)
{
return (from o in _context.DssClient_Sasid_Certified
where (o.SasId == Sasid)
join t in _context.DssClients on o.ClientId equals t.ClientId
select new
{
ClientId = o.ClientId,
SasId = o.SasId,
FormalLastName = o.FormalLastName,
FormalFirstName = o.FormalFirstName,
FormalMiddleName = o.FormalMiddleName,
BenefitSource = t.BenefitSource,
DOB = o.DOB
}).ToList();
}
您是否试图从方法返回匿名类型的列表?据我所知,这是被禁止的。 – undefined 2014-09-26 12:40:58
不要从方法返回具体类型的匿名类型。因此,在这种情况下,创建一个类“DssClient”并返回一个“List”或“IEnumerable ”是有意义的。 –
2014-09-26 12:41:05
您正在返回'List',其中T是编译器为您的选择生成的匿名类型,而您的方法需要'List ' –
2014-09-26 12:42:02