Search code examples
c#sqlwcfselectdapper

Sequence contains several elements Dapper


I'm using Dapper for retrieve a result of my request SELECT.

 List<dynamic> results = connection.Query("SELECT id_fonction from liste_personnels_fonctions where id_personnel = @id_personnel", new { id_personnel }).ToList();

But sometimes I have 2 results. When I use .SingleOrDefault() I have an exception : "Sequence contains several elements" when I have more than one row returned. When I use FirstOrDefault I have only first row and I need both of them... So what can I do? I try with List<> and var[] to retrieve the results but it doesn't work.

Any ideas? Thanks.


Solution

  • If you want just a list of Int then ask Dapper for that

    List<int> results = connection.Query<int>("SELECT id_fonction from liste_personnels_fonctions where id_personnel = @id_personnel", new { id_personnel }).ToList();