How to convert the following SQL to ServiceStack.OrmLite Sql Server format?
/* Total Receipts */
select convert(date, t.TransactionDate) [Date], tm.TeamId,a.AccountNumber, count(distinct(t.RequisitionNumber)) Total
from task.tblTransactions t
inner join task.tblRequisitions r on r.RequisitionNumber = t.RequisitionNumber
inner join task.tblAccounts a on a.AccountNumber = r.AccountNumber
inner join Team tm on tm.DivisionId = a.DivisionId
where t.TransactionTypeNumber = 201 and a.IsActive = 1
and t.TransactionDate between @fromDate and @toDate
group by convert(date, t.TransactionDate), tm.TeamName, a.AccountName
order by 1,2 desc
My Result class:
public class KpiTotal : IKpiTotal
{
public DateTime Date { get; set; }
public int TeamId { get; set; }
public Team Team { get; set; }
public int AccountId { get; set; }
public Account Account { get; set; }
public double Total { get; set; }
}
For custom SQL like this, you'd use OrmLite's Custom SQL API's, with something like:
var results = db.Select<Poco>(@"select convert(date, t.TransactionDate) [Date],
tm.TeamName, a.AccountName, count(distinct(t.RequisitionNumber)) Total
from task.tblTransactions t
inner join task.tblRequisitions r on r.RequisitionNumber = t.RequisitionNumber
inner join task.tblAccounts a on a.AccountNumber = r.AccountNumber
inner join Team tm on tm.DivisionId = a.DivisionId
where t.TransactionTypeNumber = 201 and a.IsActive = 1
and t.TransactionDate between @fromDate and @toDate
group by convert(date, t.TransactionDate), tm.TeamName, a.AccountName
order by 1,2 desc", new { fromDate = fromDate, toDate = toDate });
Where fromDate
and toDate
is your parameterized variables and Poco
is a custom type with fields that match the returned result set.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.