2012-10-01 44 views
0

任何人都可以請建議如何檢查結果集中是否有任何記錄使用Dapper ORM。如何檢查是否存在之前,在Dapper讀ORM

Customer objCustomer = null; 
using (SqlMapper.GridReader multiResult = new DapperRepository().QueryMultiple(sql, new { id = id })) 
{ 
    objCustomer = multiResult.Read<Customer>().Single(); //null exception 
} 

回答

2

是的,這樣寫:

objCustomer = multiResult.Read<Customer>().SingleOrDefault(); //return null if not exists without error 

,那麼你可以檢查:

objCustomer != null 

希望這有助於。

相關問題