Dapper의 매개 변수 확장 코드는 목록이있는 IN 쿼리를 처리하지 않지만 DapperExtensions '조건부 시스템은 IN 쿼리를 허용하고 매개 변수가 목록 유형 인 경우 같음 쿼리 조건자를 IN 쿼리로 변환합니다.
매핑을 위해 Dapper를 사용하려면 Jonathan Willcock의 sysobjects/sysindexes 쿼리를 뷰로 확장하고 결과를 나타내는 클래스를 만들 수 있습니다.
PredicateGroup query = new PredicateGroup();
List<string> tables;
tables = new List<string> { "table1", "table2" };
query.Predicates = new List<IPredicate>();
query.Predicates.Add(Predicates.Field<TableRowCounts>(f => f.TableName, Operator.Eq, tables));
List<TableRowCounts> results;
results = _connection.GetList<TableRowCounts>(query).ToList();
:
public class TableRowCounts
{
public string TableName { get; set; }
public int Records { get; set; }
}
DapperExtensions 결과를 수화 조회 : 결과에 대한
CREATE VIEW TableRowCounts
AS
SELECT t.name TableName, i.rows Records
FROM sysobjects t INNER JOIN sysindexes i ON i.ID = t.ID where t.xtype = 'U' and i.indid in (0,1)
클래스 : 그런 다음 적절한 매개 변수를
뷰 생성을 DapperExtensions GetList 쿼리를 조립 수
IN 성능에 관한 부수적 인 설명으로 성능 분석 결과를 볼 수 있습니다. op 매개 변수 목록 (이 경우 테이블 이름)이 약 200 개 항목보다 큰 경우.
어떤 데이터베이스를 사용하고 있습니까? –
SQL 서버 사용 – Manjari