검색 할 필드 조합 목록이 있습니다. 목록에는 실제로 최대 100 개의 항목이 포함될 수 있으며 쿼리하는 테이블에는 현재 1 백만 개가 넘는 레코드가 있습니다.필드 조합 목록이있는 Where 절
예 : 데이터를 검색 할
create table mytable
(
foo int not null
,bar int not null
,baz int not null
)
insert into
mytable
values
(1, 1, 11)
,(1, 2, 12)
,(1, 3, 13)
,(2, 1, 21)
,(2, 2, 22)
,(2, 3, 23)
,(3, 1, 31)
,(3, 2, 32)
,(3, 3, 33)
한 가지 가능한 방법 :
select
foo
,bar
,baz
from
mytable
where
(foo = 1 and bar = 3)
or (foo = 2 and bar = 1)
or (foo = 3 and bar = 2)
또 다른 가능한 방법 :
foo bar baz
----------- ----------- -----------
1 3 13
2 1 21
3 2 32
:
declare @filtercombos table
(
foo int not null
,bar int not null
)
insert into
@filtercombos
values
(1, 3)
,(2, 1)
,(3, 2)
select
mytable.foo
,mytable.bar
,mytable.baz
from
@filtercombos fc
left join mytable on mytable.foo = fc.foo and mytable.bar = fc.bar
모두이 데이터를 반환합니다
이제 이것이 단일 값 목록 인 경우 .Where(item => myList.Contains(item.foo))
을 할 수 있습니다. 위와 같은 쿼리를 어떻게 수행 할 수 있습니까? 내가 생각할 수있는 유일한 것은 DbContext에서 SQL을 실행하는 것이지만 가능한 경우이를 피하고 싶습니다.
이 경우 프로필러는 검색어가 ' (foo = 1 및 bar = 3) 또는 (foo = 2 및 bar = 1) 또는 (foo = 3 및 bar = 2)'로 확장되었음을 보여줍니다. – Stijn