C# mvc中对linq的SQL查询

C# mvc中对linq的SQL查询,c#,sql,linq,C#,Sql,Linq,我正在创建一个报表,其中我正在创建一个存储过程,对于一个特定的列,我需要使用以下查询 (SELECT COUNT(1) FROM [dbo].EmployeeDependent WITH (NOLOCK) WHERE [dbo].EmployeeDependent.GCPDocumentId = gdh.GCPDocumentId ) AS [No of Dependants travelling with employee] FROM tablename 整个子查询用于sql

我正在创建一个报表,其中我正在创建一个存储过程,对于一个特定的列,我需要使用以下查询

(SELECT COUNT(1) FROM [dbo].EmployeeDependent WITH (NOLOCK) 
 WHERE [dbo].EmployeeDependent.GCPDocumentId = gdh.GCPDocumentId ) 
     AS [No of Dependants travelling with employee] FROM tablename
整个子查询用于sql查询的select子句。 现在我想将此查询转换为linq,但不知何故我无法实现它


感谢您提供无锁,您需要执行以下操作:

using (var txn = new TransactionScope(
    TransactionScopeOption.Required, 
    new TransactionOptions
    {
        IsolationLevel = IsolationLevel.ReadUncommitted
    }
))
{

}
注意:您正在创建一个新的TransactionScope对象,并告诉它使用读未提交隔离级别。using语句中的查询现在的行为就好像它的所有表都在使用NOLOCK提示读取一样

您的查询将如下所示:


EmployeeDependent.GCPDocumentId=+gdh.GCPDocumentId这行是什么意思?很抱歉,查询是从[dbo]中选择COUNT1。EmployeeDependent WITH NOLOCK WHERE[dbo]。EmployeeDependent.GCPDocumentId=gdh.GCPDocumentId AS[No of Dependent Tower Traveling of employee]从TableName中基本上您想要选择查询的结果吗[随同员工旅行的家属人数]我是rit吗?我建议使用以下查询发布您的整个查询:EmployeeDependent.Wherex=>x.GCPDocumentId==gdh.GCPDocumentId.Count;如果这是子查询,您需要将该值包含到父查询中。
using (var txn = new TransactionScope(
    TransactionScopeOption.Required, 
    new TransactionOptions
    {
        IsolationLevel = IsolationLevel.ReadUncommitted
    }
))
{
    var count = from c in EmployeeDependent where c.GCPDocumentId = GCPDocumentId
    select new (DependantsTravelling = c.Count())
}