Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 优化Linq查询_.net_Linq_Linq To Sql - Fatal编程技术网

.net 优化Linq查询

.net 优化Linq查询,.net,linq,linq-to-sql,.net,Linq,Linq To Sql,我附上一个简单的LINQ查询。 我想知道是否有更好、更有效的方法来提取这三个字段(Field1、Field2、Field3),如下面的LINQ查询中所述 from currentCons in ActiveConnections join accounts in Accounts on currentCons.New_AccountId equals accounts.AccountId let Field1 =(from

我附上一个简单的LINQ查询。 我想知道是否有更好、更有效的方法来提取这三个字段(Field1、Field2、Field3),如下面的LINQ查询中所述

from currentCons in ActiveConnections
join accounts in Accounts on currentCons.New_AccountId equals accounts.AccountId                                     
let Field1 =(from holder in MapHolders
        join entity in Entities on stringmap.ObjectTypeCode equals   entity.ObjectTypeCode
        where entity.Name == "New_Connection"
        where holder.AttributeName == "New_Data"
        where holder.AttributeValue ==  currentCons.New_DATA_Val
        select holder.Value)
 let Field2=(from holder in MapHolders
        join entity in Entities on stringmap.ObjectTypeCode equals entity.ObjectTypeCode
        where entity.Name == "New_Connection"
        where holder.AttributeName == "New_Type"
        where holder.AttributeValue == currentCons.New_Type
        select holder.Value)
let Field3=(from holder in MapHolders
        join entity in Entities on stringmap.ObjectTypeCode equals entity.ObjectTypeCode
        where entity.Name == "New_Connection"
        where holder.AttributeName == "New_EntryPoint"
        where holder.AttributeValue == currentCons.New_EntryPoint
        select holder.Value)
   where currentCons.ModifiedOn >= Convert.ToDateTime("1/1/2011")
   where currentCons.ModifiedOn <= Convert.ToDateTime("5/5/2012")
   select new 
   {
      conId = currentCons.ConnectionId,
      ConName = currentCons.name,
      TypeId = currentCons.Type,
      AccountId = currentCons.AccountId,
      OId = currentCons.OwnerId,
      BandwidthId = currentCons.Bandwidth,
      EntryPointId = currentCons.EntryPoint,
      Cap = Field1 ,
      Dir=Field2,
      EP=Field3,
      ModifiedOn = currentCons.ModifiedOn
    }
来自ActiveConnections中的currentCons
在currentCons.New_AccountId等于accounts.AccountId的帐户中加入帐户
让Field1=(来自MapHolders中的holder)
在stringmap.ObjectTypeCode上的实体中联接实体等于entity.ObjectTypeCode
其中entity.Name==“新建连接”
其中holder.AttributeName==“新数据”
其中holder.AttributeValue==currentCons.New\u DATA\u Val
选择持有者。值)
让Field2=(来自MapHolders中的holder)
在stringmap.ObjectTypeCode上的实体中联接实体等于entity.ObjectTypeCode
其中entity.Name==“新建连接”
其中holder.AttributeName==“新类型”
其中holder.AttributeValue==currentCons.New\u类型
选择持有者。值)
让Field3=(来自MapHolders中的holder)
在stringmap.ObjectTypeCode上的实体中联接实体等于entity.ObjectTypeCode
其中entity.Name==“新建连接”
其中holder.AttributeName==“New\u EntryPoint”
其中holder.AttributeValue==currentCons.New\u入口点
选择持有者。值)
其中currentCons.ModifiedOn>=Convert.ToDateTime(“1/1/2011”)
你在哪里

另外,请检查Cap/Dir/EP是否可为空

您使用的是哪种LINQ提供程序?LINQ到SQL?LINQ到实体?还有别的吗?
var fromDate =  new DateTime(2011,1,1);
var toDatePlusOneDay = new DateTime(2012,5,5).AddDays(1); // add one day to ensure 

var result = from currentCons in ActiveConnections
            join accounts in Accounts on currentCons.New_AccountId equals accounts.AccountId                                     
            where currentCons.ModifiedOn >= fromDate
            where currentCons.ModifiedOn < toDatePlusOneDay 
            from holder in MapHolders
            where (holder.AttributeName == "New_Data" && holder.AttributeValue == currentCons.New_DATA_Val) || (holder.AttributeName == "New_Type" && holder.AttributeValue == currentCons.New_Type) || (holder.AttributeName == "New_EntryPoint" && holder.AttributeValue == currentCons.New_EntryPoint)
            select new 
            {
              conId = currentCons.ConnectionId,
              ConName = currentCons.name,
              TypeId = currentCons.Type,
              AccountId = currentCons.AccountId,
              OId = currentCons.OwnerId,
              BandwidthId = currentCons.Bandwidth,
              EntryPointId = currentCons.EntryPoint,
              ModifiedOn = currentCons.ModifiedOn,
              Cap = (holder.AttributeValue == currentCons.New_DATA_Val) ? holder.Value : null,
              Dir = (holder.AttributeValue == currentCons.New_Type) ? holder.Value : null,
              EP = (holder.AttributeValue == currentCons.New_EntryPoint) ? holder.Value : null              
            }   
join entity in Entities on stringmap.ObjectTypeCode equals entity.ObjectTypeCode
        where entity.Name == "New_Connection"