Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Convert IEnumerable to List

$
0
0

Hello Guys!

Somebody help me with this error?

I have this method:

public List<AnoMOD> CarregarAnos()
        {
            using (var conexao = new Entities())
            {

                return conexao.CEUS_EVENTOS.ToList().ConvertAll<AnoMOD>(x =>
                {
                    return new AnoMOD
                    {
                        dtAno = Convert.ToString(x.DTEVENTO.Year)
                    };
                }).Distinct();
            }
        }


When i try to compile, this error appears:

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<CeusPontos.WebAPI.Models.AnoMOD>' to 'System.Collections.Generic.List<CeusPontos.WebAPI.Models.AnoMOD>'. An explicit conversion exists (are you missing a cast?) E:\Projetos\CeusPontos.WebAPI\Controllers\AnoController.cs 37 19 CeusPontos.WebAPI</div>


Viewing all articles
Browse latest Browse all 4850

Trending Articles



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