2012-10-01 47 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 

希望这有助于。

相关问题