I'd like to select many values from a table with a list.
I have FabricTable
(Year is int
):
+----+-------+---------+------+
| Id | Color | Texture | Year |
+----+-------+---------+------+
| 1 | Red | Rough | 2019 |
+----+-------+---------+------+
| 2 | Green | Soft | 2019 |
+----+-------+---------+------+
| 3 | Blue | Rough | 2019 |
+----+-------+---------+------+
| 4 | Red | Med | 2019 |
+----+-------+---------+------+
| 5 | Blue | Soft | 2018 |
+----+-------+---------+------+
I have selectedItems
list (year is int
):
+---------+------+
| Texture | Year |
+---------+------+
| Rough | 2019 |
+---------+------+
| Soft | 2019 |
+---------+------+
I'd like to get the Id
from table, it should result with Id
= 1
, 2
, & 3
.
How can I achieve this with Linq in C#? I just need to select by Texture
& Year
Here's what I've tried but I'm not sure how to select from list with multiple values(selectedItems
is a list but I don't know how to query multiple columns):
db.FabricTable.Select(o => o.Texture == selectedItems.Texture && o.Year == selectItems.Year)
selectedItems.Texture
andselectedItems.Year
Where
clause will select items from the table, and each item will contain all the properties, includingId
. For filtering the items based on a list, see Andy's answer below.