Quantcast
Channel: how to convert list to IEnumerable? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by Darren for how to convert list to IEnumerable?

$
0
0

You're returning two different object types:

  • tblSoftwareImageTestPlan - Which resides in your Entity Framework model
  • SoftwareImageTestPlan - Which resides in your Qlasr Schema Models

Therefore when you state the following:

return records;

It will complain that the records object is not of type SoftwareImageTestPlan. Therefore you need to convert records into a new List<SoftwareImageTestPlan> which you can achieve via a LINQ projection.

var records = (from entities in _entities.tblSoftwareImageTestPlans
               where entities.SoftwareProductID equals SoftwareProductID && entities.SoftwareImageID == SoftwareImageId
               select new SoftwareImageTestPlan
               {
                  SoftwareProductID = entities.SoftwareProductID,
                  SoftwareImageID = entities.SoftwareImageID
               }).ToList();

You can then use your original statement:

if (records == null)
    return new List<SoftwareImageTestPlan>();
else
    return records;

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>