First of all, my English is very poor, so I may not be a very good expression, very sorry!

In this blog: EntityFramework 7 Left Join Where Select 奇怪问题, Were left join query using Linq, I probably had four different grammar test, but I tested may be some messy, so it would be more difficult to analyze, and here I only tested a grammar, this is my project is used to test the following elements:

BloggingContext configuration code:

  1. using Microsoft.Data.Entity;
  2. using Microsoft.Data.Entity.Metadata;
  3. using System.Collections.Generic;
  4. namespace EF7
  5. {
  6. public class BloggingContext : DbContext
  7. {
  8. public DbSet<Blog> Blogs { get; set; }
  9. public DbSet<BlogCate> BlogCates { get; set; }
  10. protected override void OnConfiguring(DbContextOptions builder)
  11. {
  12. builder.UseSqlServer(@"Server=.;Database=Blogging;Trusted_Connection=True;");
  13. }
  14. protected override void OnModelCreating(ModelBuilder builder)
  15. {
  16. builder.Entity<Blog>()
  17. .Key(b => b.BlogId);
  18. builder.Entity<BlogCate>()
  19. .Key(b => b.CateId);
  20. }
  21. }
  22. public class Blog
  23. {
  24. public int BlogId { get; set; }
  25. public string Url { get; set; }
  26. public int BlogCateId { get; set; }
  27. }
  28. public class BlogCate
  29. {
  30. public int CateId { get; set; }
  31. public string CateName { get; set; }
  32. }
  33. }

Note that in OnModelCreating, I did not make for BlogCate OneToMany configuration and Blog, that they do not exist ForeignKey relationship, so I did not use Include grammar.

Test code(The most important):

  1. [Fact]
  2. public void TestWithLeftJoin()
  3. {
  4. using (var context = new BloggingContext())
  5. {
  6. var query = from b in context.Blogs
  7. join c in context.BlogCates on b.BlogCateId equals c.CateId into left
  8. from c in left.DefaultIfEmpty()
  9. where b.Url == "http://www.cnblogs.com/"
  10. select new { b.BlogId, c.CateName };
  11. var result = query.ToList();
  12. }
  13. }

EF6 Test Results:

SQL Server Profiler to get SQL code:

  1. SELECT
  2. [Extent1].[BlogId] AS [BlogId],
  3. [Extent2].[CateName] AS [CateName]
  4. FROM [dbo].[Blog] AS [Extent1]
  5. LEFT OUTER JOIN [dbo].[BlogCate] AS [Extent2] ON [Extent1].[BlogCateId] = [Extent2].[CateId]
  6. WHERE N'http://www.cnblogs.com/' = [Extent1].[Url]

EF7 Test Results:

Error details:

The multi-part identifier "b.Url" could not be bound.

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)

at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)

at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)

at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()

at System.Data.SqlClient.SqlDataReader.get_MetaData()

at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)

at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)

at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)

at System.Data.Common.DbCommand.ExecuteReader()

at Microsoft.Data.Entity.Relational.Query.QueryingEnumerable1.Enumerator.MoveNext()

at System.Linq.Lookup2.CreateForJoin(IEnumerable1 source, Func2 keySelector, IEqualityComparer1 comparer)

at System.Linq.Enumerable.d__6a4.MoveNext()

at System.Linq.Enumerable.d__142.MoveNext()

at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()

at Microsoft.Data.Entity.Query.EntityQueryExecutor.EnumerableExceptionInterceptor1.EnumeratorExceptionInterceptor.MoveNext()

at System.Collections.Generic.List1..ctor(IEnumerable1 collection)

at System.Linq.Enumerable.ToList [TSource] (IEnumerable1 source)

at EF7.Tests.EF7_Test.TestWithLeftJoin() in C:\Users\yuezhongxin\Desktop\EF7\src\EF7.Tests\EF7_Test.cs:line 47

Use EF6 generated SQL code is what I want, but it is wrong to use EF7. From the test code you can see that I am asking for Url for "http://www.cnblogs.com/" The BlogId and CateName information, in Blog, BlogCateId value may be Null, so just use the Left Join, rather Inner Join. The above test code is just an example, but my project is the same, I do not know if you can understand what I mean?

Also, if I put Where conditions are removed, use EF7 is right, like this:

However, using SQL Server Profiler to get SQL code is so that:

In EF7, I personally feel that there are some problems using the Join, like this same problem: Use EF7, Linq Join Count is error. I feel they are essentially a problem.

I'm sorry I can only use these English expressions, thanks!

EntityFramework 7 Left Join Where is error(Test record)的更多相关文章

  1. EntityFramework 7 Left Join Where Select 奇怪问题

    这篇博文纪录一下:使用 EF7,当 Linq 查询中使用 "Left Join" 语法(DefaultIfEmpty),Where Select 不同条件语法实现,出现的不同问题. ...

  2. Docker -- resolve "join node timeout" error

    在worker节点机器上通过docker swarm join 到 manger node时,报Timeout错误,如下: Error response from daemon: Timeout wa ...

  3. ssl error rx record too long

  4. [Err] ERROR: wrong record type supplied in RETURN NEXT

    在写GP 输出不定长列数据表 函数时,报了一个错,百思不得其解.在公司大佬帮助下,知道是什么鬼了.. 先看看例子吧: ---- 函数定义 CREATE OR REPLACE FUNCTION &quo ...

  5. 爱与恨的抉择:ASP.NET 5+EntityFramework 7

    EF7 的纠缠 ASP.NET 5 的无助 忘不了你的好 一开始列出的这个博文大纲,让我想到了很久之前的一篇博文:恋爱虽易,相处不易:当EntityFramework爱上AutoMapper,只不过这 ...

  6. ASP.NET 5+EntityFramework 7

    爱与恨的抉择:ASP.NET 5+EntityFramework 7   EF7 的纠缠 ASP.NET 5 的无助 忘不了你的好 一开始列出的这个博文大纲,让我想到了很久之前的一篇博文:恋爱虽易,相 ...

  7. EntityFramework 7 Join Count LongCount 奇怪问题(已修复)

    问题说明: 博客问题纪录 Use EF7, Linq Join Count is error EF7 Code Commit EF7 版本(注意 rc): 旧版本:"EntityFramew ...

  8. EntityFramework 7 Join Count LongCount 奇怪问题

    先吐槽一下,EF7 目前来说,真对的起现在的版本命名:"EntityFramework": "7.0.0-beta1". 这篇博文纪录一下:当 Linq 查询中 ...

  9. rpmdb: unable to join the environment的问题解决

    今天笔者在Centos 6.3上使用yum安装lsof软件时,报如下错误: [root@ ~]# yum install lsof -y rpmdb: unable to join the envir ...

随机推荐

  1. Log4j按级别输出到不同文件

    log4j.properties 文件: log4j.logger.net.sf.hibernate.cache=debug log4j.rootLogger = error,portal_log,s ...

  2. 如果你想真正了解Struts2,不妨可以进来看看

    首先我们就一起来认识认识Struts2到底是什么?作为框架,它又是用来处理哪些问题的呢?正所谓脚踏实地走,即时离梦想会远一点,但却很真实,那我们就一步一步的来了解Struts2吧!      一.既然 ...

  3. CI框架,双层弹出框的样式实现

    在弹出的主页面上,写一个隐藏的悬浮的div 通过标记使他显示,通过计数器使他关闭 部分代码: <div id="common_msg"></div>//主页 ...

  4. eayui datagrid 分页 排序 详解

    最近因为经常使用easyui 在做表格时难免后出现排序 及分页的问题,但是 在官网中没有 相关的介绍及例子,所以经过多方面的查找后,终于完成了分页 和排序的功能 首先 页面datagrid 要排序的必 ...

  5. Oracle EBS - PO Approval

    PO Approval Except Standard Flow: 1. Personal setting

  6. Nova PhoneGap框架 第九章 控件

    我们的框架中也提供了一些常用的控件,这些控件大多都依赖于我们的框架,也正是在我们的框架下才使得实现这些控件的变得更简单.但是我们的框架是不依赖与这些控件的,如果你用不上这些控件,你完全可以把相关的代码 ...

  7. 基于zookeeper实现统一资源管理

    分布式系统中经常涉及到配置资源的管理,比如,一个应用系统需要部署在多台服务器上,但是他们拥有某些的配置项是相同的,如果配置变更,需要修改这些配置,那么需要同时修改每台服务器,这样做比较麻烦而且容易出错 ...

  8. Hadoop学习笔记—21.Hadoop2的改进内容简介

    Hadoop2相比较于Hadoop1.x来说,HDFS的架构与MapReduce的都有较大的变化,且速度上和可用性上都有了很大的提高,Hadoop2中有两个重要的变更: (1)HDFS的NameNod ...

  9. .Net开发笔记(二十)创建一个需要授权的第三方组件

    在使用需要授权的软件时,注册付费的目标是软件的使用者,我们开发人员平时用到的一些第三方组件也是需要授权付费的,也就是说,付费者是开发人员,并不是系统(使用了该第三方组件)的最终使用者. 以上两者的区别 ...

  10. 大白话讲解Promise(三)搞懂jquery中的Promise

    前两篇我们讲了ES6中的Promise以及Promise/A+规范,在Promise的知识体系中,jquery当然是必不可少的一环,所以本篇就来讲讲jquery中的Promise,也就是我们所知道的D ...