Linq2Sql选择sum,in,left和nolock查询

时间:2013-11-06 16:20:05

标签: c# sql sql-server linq linq-to-sql

我如何使用Linq2Sql上下文在linq中编码此查询?

select SUM(ORDERQTY * MULTIPLIER) AS VOL_USD
   from Executions with (nolock)
where TRANSACTTIME >= '2013-08-01 00:00:00'
and TRANSACTTIME < '2013-09-01 00:00:00'
and MTCONTEXT in (5,6)
and ORDERQTY > 0
AND SOURCE = 'INTMT'
and LEFT(SYMBOL, 3) = 'USD'

是否可以让Linq2Sql生成的查询与纯SQL查询相同?

1 个答案:

答案 0 :(得分:1)

你可以使用这样的东西

using (var ts = new TransactionScope(TransactionScopeOption.Required,
                new TransactionOptions {IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted}))
{
    var result = DbContext.Executions.Where(/*...condition...*/).Sum(o=>o.ORDERQTY * o.MULTIPLIER)
}