[英]Convert SQL to ServiceStack.ORMLite Sql Server
How to convert the following SQL to ServiceStack.OrmLite Sql Server format? 如何将以下SQL转换为ServiceStack.OrmLite Sql Server格式?
/* 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: 对于像这样的自定义SQL,您可以使用OrmLite的自定义SQL API,其内容如下:
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. 其中
fromDate
和toDate
是您的参数化变量,而Poco
是自定义类型,其字段与返回的结果集匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.