Problem is not in convertation of List<T>
to IEnumerable<T>
. Becuase List<T>
implements IEnumerable<T>
.
Your problem is that generic parameters are different. You are trying to convert List<T1>
to IEnumerable<T2>
. Where:
- T1 is
QlasrService.EntityFramework.tblSoftwareImageTestPlan
- T2 is
QlasrService.Model.SchemaModels.LAP.SoftwareImageTestPlan
Simplest solution will be mapping (either manual or automatic). Automatic mapping is very easy. Add Automapper nuget package. Place this line somewhere on application start:
Mapper.Initialize(cfg => cfg.CreateMap<tblSoftwareImageTestPlan, SoftwareImageTestPlan>());
And now your method will look like:
public IEnumerable<SoftwareImageTestPlan> GetAssignedTestPlansForSPSI(
int SoftwareProductID, int SoftwareImageID)
{
var testPlans = from tp in _entities.tblSoftwareImageTestPlans
where tp.SoftwareProductID == SoftwareProductID && tp.SoftwareImageID == SoftwareImageID
select tp;
return Mapper.Map<IEnumerable<SoftwareImageTestPlan>>(testPlans);
}
NOTE: In your code either records
cannot have null
value, or you will have NullReferenceException
at ToList()
call. So if..else
block is useless anyway.