I have a list of objects that I retrieved from a web service call and I need to match them up against some rows in one of my database tables. My object has a few properties:
Name - string
Type - string
Together Name and Type would bring back a unique item in my database:
SELECT * FROM dbo.MyTable WHERE SomeName = @Name AND SomeType = @Type
This works fine; however, I have a list of Name/Type pairs and need to match against rows in my database:
List<Tuple> values = [{ "Name1", "Type1" }, { "Name2", "Type2" }, { "Name3", "Type3" }]
How could i write a query in SQL that would return a list of items based on a list of tuples. The format above is not actually the format of my values, so don’t worry about writing some parsing logic to get the values.
You could use Table-Valued Parameters in SQL Server 2008 (ADO.NET).
SQL
C#