Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.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
C# 实体框架使用include和order by生成低效查询_C#_Sql Server_Entity Framework - Fatal编程技术网

C# 实体框架使用include和order by生成低效查询

C# 实体框架使用include和order by生成低效查询,c#,sql-server,entity-framework,C#,Sql Server,Entity Framework,1) 我遇到的第一个问题是,如果执行一个include,然后SQL生成的一个order生成一个内部连接和一个外部连接 var query = from l in Lead.Include("Contact") orderby l.Contact.FirstName select l; 在同一个表上生成以下内部联接和外部联接 INNER JOIN [dbo].[Contact] AS [Extent2] ON [Extent1].[ContactId] = [Extent2].[

1) 我遇到的第一个问题是,如果执行一个include,然后SQL生成的一个order生成一个内部连接和一个外部连接

var query = from l in Lead.Include("Contact")
orderby l.Contact.FirstName
select l;
在同一个表上生成以下内部联接和外部联接

 INNER JOIN [dbo].[Contact] AS [Extent2] 
      ON [Extent1].[ContactId] = [Extent2].[ContactId]
 LEFT OUTER JOIN [dbo].[Contact] AS [Extent3] 
      ON [Extent1].[ContactId] = [Extent3]. [ContactId]
ORDER BY [Extent2].[FirstName] ASC
这使得查询效率有点低

2) 如果我做多个包含,它总是做第二个作为外部连接

 Lead.Include("OneToOne").Include("OtherOneToOne") <- in this scenario     
                                                      OtherOneToOne is an outer 
                                                     join and OneToOne is an inner 
                                                     join
 Lead.Include("OtherOneToOne").Include("OneToOne") <- in this scenario 
                                                      OneToOne is an outer join 
                                                      and OtherOneToOne is an 
                                                      inner join

Lead.Include(“OneToOne”)。Include(“OtherOneToOne”)一个解决方案是让您自己包括:

var query = from l in Lead
select new { l, l.Contact } into row
orderby row.Contact.FirstName
select row;

嗯,事实上,我不认为我设置了正确的使用ctp。。。。。它似乎和RIA玩得不好。。。。让我们看看。。。。