如何在使用LINQ使用SQL Server表提示? [英] How to use SQL Server table hints while using LINQ?

查看:187
本文介绍了如何在使用LINQ使用SQL Server表提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是使用SQL Server的表提示,如NOLOCK,而使用LINQ的方式吗?

What is the way to use Sql Server's table hints like "NOLOCK" while using LINQ?

例如,我可以写SELECT * FROM员工(NOLOCK)的SQL。

For example I can write "SELECT * from employee(NOLOCK)" in SQL.

我们如何能写出使用LINQ一样吗?

How can we write the same using LINQ?

推荐答案

下面是如何应用NOLOCK:的http://www.hanselman.com/blog/GettingLINQToSQLAndLINQToEntitiesToUseNOLOCK.aspx

Here's how you can apply NOLOCK: http://www.hanselman.com/blog/GettingLINQToSQLAndLINQToEntitiesToUseNOLOCK.aspx

(行情留给后人,由斯科特先生保留所有权利):

(Quote for posterity, all rights reserved by mr scott):

ProductsNewViewData viewData = new ProductsNewViewData();
using (var t = new TransactionScope(TransactionScopeOption.Required,
    new TransactionOptions { 
        IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted 
    }))
{
   viewData.Suppliers = northwind.Suppliers.ToList();
   viewData.Categories = northwind.Categories.ToList();
}

这篇关于如何在使用LINQ使用SQL Server表提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆