get field of a list of duplicate ids RRS feed

  • Question

  • User-1106823036 posted

    I have a list of customer Ids custIds={1,2,1,3,2}

    I want to get the name of each id

    so I do the following

     var custNmes = db.customers.Where(m => custIds.Contains(m.id)).SelectMany(m => m.name).ToList();

    but this would return the names of ids={1,2,3} it groups the dulicate ids

    what I really want is to have all names even if duplicate

    how could that happen please

    Thursday, June 4, 2015 5:57 AM


  • User-1965857832 posted

    This should do

    var custNames = custIds.Select(x => db.customers.Single(y => y.id == x).name).ToList();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 4, 2015 6:18 AM