c# - Select statement using list of key value pairs in where clause -
i want figure out way using entity framework, i'll settle sql it. given list of key value pairs, there way select rows table table.cola = item.key , table.colb = item.value?
for instance given next table data:
cola colb colc ------------------ 1 3 abc 1 3 def 5 6 abc 5 8 def 9 10 abc 9 3 def
and next list:
[{1, 3}, {5, 6}, {9, 3}]
i next rows returned:
cola colb colc ------------------ 1 3 abc 1 3 def 5 6 abc 9 3 def
so resulting query need impact of:
select * tabledata (cola = 1 , colb = 3) or (cola = 5 , colb = 6) or (cola = 9 , colb = 3)
the cleanest way utilize table-valued parameters. inner bring together on table parameter , target table retrieve rows table.
see this msdn article specifics on using table-valued parameters.
if working sql versions prior 2008, or don't want utilize table-valued parameters, can concatenate 2 values , utilize in clause, like:
select * mytable cast(cola varchar(10)) + '|' + cast(colb varchar(10)) in ('1|3', '5|6', '9|3')
c# sql sql-server entity-framework
No comments:
Post a Comment