I am new to LINQ I am getting this error
Cannot implicitly convert type
System.Collections.Generic.List<AnonymousType#1>
toSystem.Collections.Generic.List<DirCert.Data.Model.DssClient_Sasid_Certified>
I can't figure out how to solve this error.
Here is my code:
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();
}
Your select clause:
select new
{
...
}
is selecting an anonymous type. You need it to select a DssClient_Sasid_Certified
, so that you can return the type that your method declaration says you're going to return. You may just need to change your code to:
select new DssClient_Sasid_Certified
{
...
}
... assuming DssClient_Sasid_Certified
has all the properties you're setting, of course.
See more on this question at Stackoverflow