博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用LINQPad调试Linq和Entity Framework
阅读量:6253 次
发布时间:2019-06-22

本文共 4416 字,大约阅读时间需要 14 分钟。

         可以Load一个包含有EF Model的程序集。这样极大的方便调试LINQ.而不需要VisualStudio, 让我们来演示一下。首选创建一个Connection,看下图:

通过点击Browse加载一个程序集,然后你可以看左右的目录树结构:

 

输入这样的LINQ Expression:

1:                  from forumGroupMapping in ForumGroupMappings
2:                   join forumGroup in ForumGroups
3:                   on forumGroupMapping.ForumGroupId equals forumGroup.Id
4:   
5:                   join teamForumGroupMapping in TeamForumGroupMappingAccesses
6:                   on forumGroupMapping.Id equals teamForumGroupMapping.ForumGroupMappingId
7:   
8:                   join teamRole in TeamRoleAgentMappings
9:                   on teamForumGroupMapping.TeamId equals teamRole.TeamId
10:   
11:                   join team in Teams
12:                   on teamRole.TeamId equals team.Id
13:   
14:                   where team.IsActive.Equals(true) &&
15:                   team.IsDeleted.Equals(false) &&
16:                   teamRole.IsActive.Equals(true) &&
17:                   teamRole.IsDeleted.Equals(false) &&
18:                   teamForumGroupMapping.IsActive.Equals(true) &&
19:                   teamForumGroupMapping.IsDeleted.Equals(false) &&
20:                   forumGroupMapping.IsActive.Equals(true) &&
21:                   forumGroupMapping.IsDeleted.Equals(false) &&
22:                   forumGroup.IsActive.Equals(true) &&
23:                   forumGroup.IsActive.Equals(true) &&
24:                   teamRole.AgentId.Equals(new Guid("476c261f-b25a-4c0b-ba06-f3c9f7b00eeb"))
25:                  select forumGroupMapping
 
执行后可以看到这个T-SQL:
1:  SELECT
2:  [Filter2].[Id1] AS [Id],
3:  [Filter2].[ForumGroupId] AS [ForumGroupId],
4:  [Filter2].[ForumId] AS [ForumId],
5:  [Filter2].[RootForumId] AS [RootForumId],
6:  [Filter2].[RootForumExternalId] AS [RootForumExternalId],
7:  [Filter2].[PlatformTypeId] AS [PlatformTypeId],
8:  [Filter2].[Locale] AS [Locale],
9:  [Filter2].[CreatedBy1] AS [CreatedBy],
10:  [Filter2].[CreatedDate1] AS [CreatedDate],
11:  [Filter2].[LastUpdatedBy1] AS [LastUpdatedBy],
12:  [Filter2].[LastUpdatedDate1] AS [LastUpdatedDate],
13:  [Filter2].[IsActive1] AS [IsActive],
14:  [Filter2].[IsDeleted1] AS [IsDeleted]
15:  FROM   (SELECT [Filter1].[Id1], [Filter1].[ForumGroupId], [Filter1].[ForumId], [Filter1].[RootForumId], [Filter1].[RootForumExternalId], [Filter1].[PlatformTypeId], [Filter1].[Locale], [Filter1].[CreatedBy1], [Filter1].[CreatedDate1], [Filter1].[LastUpdatedBy1], [Filter1].[LastUpdatedDate1], [Filter1].[IsActive1], [Filter1].[IsDeleted1], [Filter1].[TeamId1], [Extent4].[TeamId] AS [TeamId2]
16:      FROM   (SELECT [Extent1].[Id] AS [Id1], [Extent1].[ForumGroupId] AS [ForumGroupId], [Extent1].[ForumId] AS [ForumId], [Extent1].[RootForumId] AS [RootForumId], [Extent1].[RootForumExternalId] AS [RootForumExternalId], [Extent1].[PlatformTypeId] AS [PlatformTypeId], [Extent1].[Locale] AS [Locale], [Extent1].[CreatedBy] AS [CreatedBy1], [Extent1].[CreatedDate] AS [CreatedDate1], [Extent1].[LastUpdatedBy] AS [LastUpdatedBy1], [Extent1].[LastUpdatedDate] AS [LastUpdatedDate1], [Extent1].[IsActive] AS [IsActive1], [Extent1].[IsDeleted] AS [IsDeleted1], [Extent3].[TeamId] AS [TeamId1]
17:          FROM   [dbo].[ForumGroupMapping] AS [Extent1]
18:          INNER JOIN [dbo].[ForumGroup] AS [Extent2] ON [Extent1].[ForumGroupId] = [Extent2].[Id]
19:          INNER JOIN [dbo].[TeamForumGroupMappingAccess] AS [Extent3] ON [Extent1].[Id] = [Extent3].[ForumGroupMappingId]
20:          WHERE (1 = [Extent1].[IsActive]) AND (0 = [Extent1].[IsDeleted]) AND (1 = [Extent2].[IsActive]) AND (1 = [Extent2].[IsActive]) AND (1 = [Extent3].[IsActive]) AND (0 = [Extent3].[IsDeleted]) ) AS [Filter1]
21:      INNER JOIN [dbo].[TeamRoleAgentMapping] AS [Extent4] ON [Filter1].[TeamId1] = [Extent4].[TeamId]
22:      WHERE (1 = [Extent4].[IsActive]) AND (0 = [Extent4].[IsDeleted]) AND (cast('476c261f-b25a-4c0b-ba06-f3c9f7b00eeb' as uniqueidentifier) = [Extent4].[AgentId]) ) AS [Filter2]
23:  INNER JOIN [dbo].[Team] AS [Extent5] ON [Filter2].[TeamId2] = [Extent5].[Id]
24:  WHERE (1 = [Extent5].[IsActive]) AND (0 = [Extent5].[IsDeleted])
同时你可以查看这个查询生成IL。这里就不截图了。

LINQPad 支持 C# 4.0 和 Framework 4.0 :

  • LINQ to Objects
  • LINQ to SQL and Entity Framework
  • LINQ to XML
  • Parallel LINQ

您还能查询:

  • OData / WCF Data Services - , and
  • SQL Azure, Oracle, SQLite and MySQL
  • (Even !)
     

希望这篇POST对您开发有帮助。

作者:
出处:
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
该文章也同时发布在我的独立博客中-。

你可能感兴趣的文章
如何提高团队管理能力1
查看>>
Redmine中使用SVN进行版本管理经验总结
查看>>
【OC语法要闻速览】一、方法调用
查看>>
使用光标
查看>>
find命令之exec
查看>>
Modular Inverse(模逆元,扩展欧几里德)
查看>>
找出两个文本文件的不同的行
查看>>
练习PYTHON之GEVENT
查看>>
Web持久化存储Web SQL、Local Storage、Cookies(常用)
查看>>
Libsvm和Liblinear的使用经验谈
查看>>
php生成curl命令行
查看>>
PHP中的数据库四、mongodb
查看>>
品读吴军"之"系列
查看>>
Android NumberPicker 修改分割线颜色和高度及字体颜色大小
查看>>
树莓派键盘布局修正
查看>>
Android之Http通信——3.Android HTTP请求方式:HttpURLConnection
查看>>
C++智能指针--weak_ptr
查看>>
HDURevenge of Segment Tree(第二长的递增子序列)
查看>>
Json数组操作小记 及 JSON对象和字符串之间的相互转换
查看>>
常量,字段,构造方法 调试 ms 源代码 一个C#二维码图片识别的Demo 近期ASP.NET问题汇总及对应的解决办法 c# chart控件柱状图,改变柱子宽度 使用C#创建Windows服...
查看>>