天天看點

Dapper 參數化查詢 ,随筆

Dapper 參數化查詢:

 對于此種查詢:id in(1,2,3,4) ,code in('a','b','c')    ,傳參:List<int> id  ,List<string> code  .實列如下:

public List<Evaluation_SelfAssessment_details_ChildEntity> GetChildListByIndexIds(int selfId, List<int> indexIds)
        {
            DynamicParameters Parameters = new DynamicParameters();
            Parameters.Add("SelfId", selfId);
            Parameters.Add("indexIds", indexIds);
            string sql = @"SELECT a.id,a.IndexId,a.ChildId,a.Indexvalue_Code,a.Indexvalue
                        FROM [dbo].[Evaluation_SelfAssessment_details_Child] a WHERE [email protected] AND a.IndexId IN @indexIds ";
            return _Respository.GetListWithSql(sql, Parameters);
        }