Good answers answer, but do not forget one IMPORTANT thing - they give different results!
var idList = new int[1, 2, 2, 2, 2];
This will return two rows from the database (and this may be correct if you only want a separate sorted list of users)
BUT , in many cases, you may need an od sorted list od. You should always think of it as an SQL query. Please see the shopping cart example to illustrate what happens:
var priceListIDs = new int[1, 2, 2, 2, 2]; // user has bought 4 times item ID 2 var shoppingCart = _dataContext.ShoppingCart .Join(priceListIDs, sc => sc.PriceListID, pli => pli, (sc, pli) => sc) .ToList();
This will return 5 results from the database. Using 'contains' would be wrong in this case.
Tomino Feb 04 '16 at 18:09 2016-02-04 18:09
source share