I have the following scenario:
a list of int: List<int> idsOnly = new List<int>();
and another list of object that should bring all items that their ids matching the list idsOnly
var myList = db.Items.Where(item => idsOnly.Contains(item.ID.Value))
.Select(a => new { a.Title })
.ToList();
I only need to get the titles from the myList
Any help will be appreciated
Your code works but it will create the list of anonymous object, not string type
Instead of using (a => new { a.Title }
, you just use a => a.Title
if you just only want to get the title:
var myList = db.Items.Where(item => idsOnly.Contains(item.ID.Value))
.Select(a => a.Title).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With