使用dapper框架动态拼接出最安全的sql语句--多条件查询
publicList<NoticeState>GetNoticeByToUserID(Searchsearch){//search.userId=3;stringsql="select*fromNoticesWHEREID>0";varparam=newDynamicParameters();sql+="ANDToUserIDLIKE@toUserID";param.Add("toUserID","%"+search.userId.ToString()+"%");if(search.ID>0){sql+="ANDid=@id";param.Add("id",search.ID);}varNoticeState=newList<NoticeState>();NoticeState.AddRange(_workingDB.Query<NoticeState>(sql,param).ToList());stringsql2="select*fromIsReadNoticeswhereNoticeID=@noticeIDANDUserID=@uid";foreach(varninNoticeState){IsReadNoticeisReadNotices=_workingDB.Query<IsReadNotice>(sql2,new{noticeID=n.ID,uid=search.userId}).SingleOrDefault();if(isReadNotices!=null){n.statusMsg=isReadNotices.statusMsg;n.Remarks=isReadNotices.Remarks;}}returnNoticeState;}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。