我想在此查询中data.Task = 0时返回所有记录。怎么做?
var data = SqlConn.ConnectSQL().Query("Select TicketNo, PickName From TaxiTicket Where DriverID = @ID AND Status = @State",
new { ID = find.Account, State = data.Task });
答案 0 :(得分:0)
var data = SqlConn.ConnectSQL().Query("Select TicketNo, PickName From TaxiTicket
Where DriverID = @ID AND (Status = case @State when 0 then Status else @state end)",
new { ID = find.Account, State = data.Task });
这仅解决您的问题,如何准备和传递参数是另一个问题。您似乎使用相同的data
变量有一些奇怪的分配。