此查询的亚音速等效查询

时间:2011-11-09 14:34:23

标签: asp.net mysql subsonic3

有人可以为我提供以下MySQL查询的等效查询:

string qry = "select @rownum := @rownum + 1 AS rowno, b_eventid as EventID,b_eventdata as 
                     EventData,b_machinetimestamp as MachineTime,b_hosttimestamp as HostTime";
       qry = qry + " from bm_transaction, (select @rownum := 0) r where b_terminalid=" +                      
                                 tid + " order by b_hosttimestamp desc";
          MySqlDataAdapter adp = new MySqlDataAdapter(qry, sqlcon);
            adp.Fill(dtLogs);

我的SubSonic查询示例是这样的:

DataTable dtlogs=new DataTable();
    try{
        arithmaticdataDB db=new arithmaticdataDB();
        IDataReader drreader=db.SelectColumns("b_eventid as EventID,b_eventdata as EventData,b_machinetimestamp as MachineTime,b_hosttimestamp as HostTime")
                              .From(" bm_transaction").Where("b_terminalid").IsEqualTo(tid).OrderDesc("b_hosttimestamp").ExecuteReader();

如何在SubSonic 3.0.0.4中将上述内容更改为我的ADO.NET查询? 任何指导都很明显。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,第一个查询是带有值注入和重命名列的原始SQL。第二个例子似乎使用了SubSonic 2.x表达式API。

在SubSonic 3中,我主要使用ActiveRecord和Linq。您的查询(非常粗略)可能如下所示:

var event_rows = b_transaction
  .Where(x => x.b_terminalid == tid)
  .OrderByDescending(x => x.hosttimestamp)
  .ToList();