c# - Linq query “where [column] in (list of values)” that return single value for each values? -


let have linq code (in linqpad):

list<string> list = new list<string>(); list.add("1611080010"); list.add("1611080011"); list.add("wrongid");  var result = orders.asqueryable().where(y => list.contains(y.id)); // , yes ids string sample result.dump(); // display result in linqpad result.count(); // equal 2 

is possible improve query force system return 1 element each of list element or throw exception? if have 3 values in list should have 3 values in result?

on question: is possible improve query force system return 1 element each of list element or throw exception:

var result = orders.asqueryable().singleordefault(y => list.contains(y.id)); 

singleordefault

returns element of sequence, or default value if sequence empty; method throws exception if there more 1 element in sequence.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -