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.
SingleOrDefaultthrows an exception if there is more than 1. That is by design. if you want the first useFirstOrDefault. If you need (up to) two of them useTake(2).ToList(). If you need all useToList(). - mjwillsSelect(z => z.id_fonction).ToList()becauseid_fonctionis the column name. - mjwills