var query1 = from c in db.Catalogue join l in db.Live on c.LiveId equals l.Id where c.StartDate < date select new{ c, l}; total = query1.Count();//生成的sql语句无join var list = query1.ToList();//生成的sql语句有join
count()后生成的语句
SELECT [GroupBy1].[A1] AS [C1] FROM ( SELECT COUNT(1) AS [A1] FROM [dbo].[Live_Catalogue] AS [Extent1] WHERE [Extent1].[StartDate] < '2016/8/19 16:24:06' ) AS [GroupBy1]
ToList()生成的语句
SELECT [Extent1].[Id] AS [Id], [Extent1].[LiveId] AS [LiveId], [Extent1].[ChapterId] AS [ChapterId], [Extent1].[RoomId] AS [RoomId], [Extent1].[TeacherId] AS [TeacherId], [Extent1].[Title] AS [Title], [Extent1].[ParentId] AS [ParentId], [Extent1].[StartDate] AS [StartDate], [Extent1].[EndDate] AS [EndDate], [Extent1].[OrderId] AS [OrderId], [Extent1].[ClientNum] AS [ClientNum], [Extent1].[VideoUrl] AS [VideoUrl], [Extent2].[Id] AS [Id1], [Extent2].[Title] AS [Title1], [Extent2].[SubscriptionNum] AS [SubscriptionNum], [Extent2].[ImageUrl] AS [ImageUrl], [Extent2].[TeacherId] AS [TeacherId1], [Extent2].[QQGroup] AS [QQGroup], [Extent2].[QQGroupUrl] AS [QQGroupUrl], [Extent2].[QQCodeUrl] AS [QQCodeUrl], [Extent2].[MyClassId] AS [MyClassId], [Extent2].[Introduction] AS [Introduction], [Extent2].[Content] AS [Content], [Extent2].[FitCrowd] AS [FitCrowd], [Extent2].[IsEnabled] AS [IsEnabled], [Extent2].[ClassId] AS [ClassId], [Extent2].[RoomId] AS [RoomId1], [Extent2].[IsFree] AS [IsFree], [Extent2].[IsSingleDirectory] AS [IsSingleDirectory] FROM [dbo].[Live_Catalogue] AS [Extent1] INNER JOIN [dbo].[Live] AS [Extent2] ON [Extent1].[LiveId] = [Extent2].[Id] WHERE [Extent1].[StartDate] < '2016/8/19 16:24:06'
2个表都没设置主外键关系
为什么Count()出的SQL语句没有生成JOIN
你应该是看错了
这绝不是看错了。
@sky_net: [dbo].[Live_Catalogue]这个表是哪里来的
@jello chen: 一个主表一个从表