我有一个 SQL 语句,里面有一堆 NOLOCK。在做了一些研究之后,我发现了一种在 LINQ to SQL 中处理这个问题的方法。这是我的做法:
int year = 2011;
int quarter = 4;
DateTime timeframe = new DateTime(year, (quarter * 3), 01).AddMonths(1);
using (var txn = new TransactionScope(
TransactionScopeOption.Required,
new TransactionOptions
{
IsolationLevel = IsolationLevel.ReadUncommitted
}))
{
// Your LINQ to SQL query goes here
var results =
from wo in WORKORDERs
join wot in WORKORDERTYPEs on wo.Wot_oi equals wot.Wotyoi
join pri in PRIORITies on wo.Prio_oi equals pri.Priooi
join s in SITEs on wo.BEparn_oi equals s.Siteoi
where wo.Audt_created_dttm.Value.Year >= year - 3 && wo.Audt_created_dttm.Value.Year >= 2006
&& wo.Audt_created_dttm < timeframe && (s.Id =="NM" || s.Id == "TH") &&
(!wot.Id.Contains("stand") && wo.Ci_cnc_date != null && pri.Prioid != "1 - Routine") &&
(pri.Prioid.Contains("1") || pri.Prioid.Contains("2") || pri.Prioid.Contains("3"))
select new {PM = wo.Wosource, Site = s.Id, Priority = pri.Prioid, Worktype = wot.Id,
WoNumber = wo.Id, Description = wo.Aenm, CreateDate = wo.Audt_created_dttm,
CloseDate = wo.Clsdt_date, Planning =
(pri.Prioid == "1 - Routine" || pri.Prioid == "6 - Planned Outage") ? "Planned" : "Unplanned"};
}
问题是我收到此错误并且找不到任何信息。
'IsolationLevel' is an ambiguous reference between 'System.Data.IsolationLevel' and 'System.Transactions.IsolationLevel'
Cannot implicitly convert type 'System.Data.IsolationLevel' to 'System.Transactions.IsolationLevel'. An explicit conversion exists (are you missing a cast?)