如何在dapper中查询多个结果以指定值

时间:2019-04-26 16:17:40

标签: c# sql dapper

我想在此查询中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 });

1 个答案:

答案 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变量有一些奇怪的分配。