用EF實現多條件查詢

2021-07-04 18:15:01 字數 1134 閱讀 8887

基本思想:首先將資料全部查出來,然後根據搜尋條件去除資料

**例項:

//將資料庫全部資料查出

var temp = db.knowledge.asnotracking().where(u => true);

//是否包含查詢模組

if (!string.isnullorempty(moduleid))

decimal moduid =convert.todecimal(moduleid);

temp =temp.where(u => u.module_id==moduid);  

//是否查詢類別

if (!string.isnullorempty(categoryid))

int category_id =convert.toint32(categoryid);

category category =categorydal.getcategory(category_id);

string fids = category.fids+","+categoryid;

decimal cateid =convert.todecimal(categoryid);

temp =temp.where(u => u.category_id ==cateid||u.category.fids.toupper().contains(fids.toupper()));

//是否查詢標題

if(!string.isnullorempty(knowtitle))

temp =temp.where(u => u.knowledge_title != null &&u.knowledge_title.toupper().contains(knowtitle.toupper()));

//對結果集進行分頁查詢

var knowledgelist = temp.where(u =>true).orderbydescending(u =>u.knowledge_id).skip((pageindex - 1) *pagesize).take(pagesize);

//對結果集總記錄數進行統計

count = temp.count();

listlist = knowledgelist.tolist();

return list;

EF多條件查詢擴充套件

帶分頁的查詢 頁碼 頁容量 條件 lambda表示式 排序 lambda表示式 iqueryablegetpagedlist int pageindex,int pagesize,expression wherelambda,expression orderbylambda,bool isasc t...

Jedis 實現多條件查詢

這裡面訪問redis的key和value全部都先序列化了的 public class defaultjedispoolclient return sinter finally public void sadd string key,string.macs finally public void hm...

PHP例項 用PHP簡單實現多條件查詢

在我們的 設計過程中,經常會用到多條件查詢,本文的原始碼是乙個二手房屋查詢的例子。在本例中,我們要實現能夠通過地理位置,物業型別,房屋 房屋面積及資訊發布日期等多個條件查詢到客戶所需的資料。查詢檔案 search.php 一 生成查詢語句 12 conn mysql connect localhos...