0

我有一个 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?)
4

2 回答 2

4

它看起来像这样的代码:

new TransactionOptions
{
    IsolationLevel = IsolationLevel.ReadUncommitted
}

应该:

new TransactionOptions
{
    IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
}
于 2012-05-31T16:02:12.667 回答
2

如果我猜的话,你对和都有一个using声明。问题是在这两种类型中都有一个名为 IsolationLevel 的类型,编译器不知道该使用哪一种。删除 System.Data 引用,或者执行System.DataSystem.Transactions

new TransactionOptions
{
    IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
}
于 2012-05-31T16:02:10.420 回答