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

Answer by Kenneth for how to convert list to IEnumerable?

$
0
0

The problem here isn't that you need to convert from List to IEnumerable.

The problem is that you're trying to convert from List<tblSoftwareImageTestPlan> to IEnumerable<SoftwareImageTestPlan>

Those are two completely different types, because of the type argument.

Possible solutions:

  • Change the return type to IEnumerable<tblSoftwareImageTestPlan>
  • Map the objects to SoftwareImageTestPlan by projecting the tblSoftwareImageTestPlan to a SoftwareImageTestPlan:

    public IEnumerable<SoftwareImageTestPlan> GetAssignedTestPlansForSPSI(int softwareProductID, int SoftwareImageID)
    {
        var records = _entities.tblSoftwareImageTestPlans
                               .Where(x => 
                                 x.SoftwareProductID == SoftwareProductID && 
                                 x.SoftwareImageID == SoftwareImageID)
                               .Select(x => new SoftwareTestPlan { 
                                 Id = Id,  // example
                                 ... do more mapping here  
                                })
                               .ToList();
    
        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>