我想編寫一個方法來查詢表使用Ormlite 這裏的SqlExpressionVisitor空cheking參數一個方法ServiceStack Ormlite SqlExpressionVisitor空檢查是我的方法:在擴展
public static List<UserChatsDTO> GetUserChats(int startRow, int rowCount, DateTime? startDate, DateTime? endDate, string operatorName, short? rating, string visitorName)
{
using (IDbConnection db = DbFactory.OpenDbConnection())
{
SqlExpressionVisitor<UserChatsDTO> ev = OrmLiteConfig.DialectProvider.ExpressionVisitor<UserChatsDTO>();
ev.Where(q =>
(startDate.HasValue && q.Dated >= startDate) &&
(endDate.HasValue && q.Dated <= endDate) &&
(!string.IsNullOrEmpty(operatorName) && q.TakenByUser.Contains(operatorName)) &&
(rating.HasValue && q.Rating == (short)rating) &&
(!string.IsNullOrEmpty(visitorName) && q.VisitorName.Contains(visitorName)));
//ev.OrderBy();
ev.Limit(startRow, rowCount);
return db.Select<UserChatsDTO>(ev);
}
}
但對象未設置到一個對象的一個實例。當我調用ev.Where部分時引發NullReferenceException。
這裏有一個錯誤,或者我錯過了什麼嗎? 謝謝。
我仍然得到這種方法的NullReferenceException。我添加了一個工作解決方案。 – 2013-12-18 17:06:09