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:

using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Metadata;
using System.Collections.Generic; namespace EF7
{
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<BlogCate> BlogCates { get; set; } protected override void OnConfiguring(DbContextOptions builder)
{
builder.UseSqlServer(@"Server=.;Database=Blogging;Trusted_Connection=True;");
} protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<Blog>()
.Key(b => b.BlogId);
builder.Entity<BlogCate>()
.Key(b => b.CateId);
}
} public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public int BlogCateId { get; set; }
}
public class BlogCate
{
public int CateId { get; set; }
public string CateName { get; set; }
}
}

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):

[Fact]
public void TestWithLeftJoin()
{
using (var context = new BloggingContext())
{
var query = from b in context.Blogs
join c in context.BlogCates on b.BlogCateId equals c.CateId into left
from c in left.DefaultIfEmpty()
where b.Url == "http://www.cnblogs.com/"
select new { b.BlogId, c.CateName };
var result = query.ToList();
}
}

EF6 Test Results:

SQL Server Profiler to get SQL code:

SELECT
[Extent1].[BlogId] AS [BlogId],
[Extent2].[CateName] AS [CateName]
FROM [dbo].[Blog] AS [Extent1]
LEFT OUTER JOIN [dbo].[BlogCate] AS [Extent2] ON [Extent1].[BlogCateId] = [Extent2].[CateId]
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. JVM中对象的销毁

    1.可达性分析算法: 可达性分析算法用来寻找将要销毁的对象,它的基本思路是:通过一系列的称为“GC ROOTs”的对象作为起始点,从这些节点开始向下搜索,搜索所走过的路径成为引用链,当一个对象到GC ...

  2. java反射技术详解

    反射: 其实就是动态的从内存加载一个指定的类,并获取该类中的所有的内容. 反射的好处:大大的增强了程序的扩展性. 反射的基本步骤: 1. 获得Class对象,就是获取到指定的名称的字节码文件对象. 2 ...

  3. 一台linux真实机实现多台Tomcat服务

    一.事前准备 ü 确保linux并未安装tomcat (这里虚拟机测试) ü 下载jdk与tomcat ① jdk-6u18-ea-bin-b01-linux-i586-20_aug_2009.bin ...

  4. bgp多线

    BGP(边界网关协议)主要用于互联网AS(自治系统)之间的互联,BGP的最主要功能在于控制路由的传播和选择最好的路由. 中国网通 .中国电信.中国铁通.教育网和一些大的民营IDC运营商都具有AS号,全 ...

  5. window.location.href 中文乱码问题。。。。

    window.location.href 中文乱码问题.... 要解决此问题需要两次解码, 第一次解码: 是在页面中的js脚本中解码:window.location.href = "save ...

  6. Visual Studio “14” CTP 4

    微软发布于10月6日发布了Visual Studio "14"CTP 4,本次发布的更新主要包括:ASP.NET vNext runtime和一些工具的优化(ASP.NET vNe ...

  7. IE7中使用Jquery动态操作name问题

    问题:IE7中无法使用Jquery动态操作页面元素的name属性. 在项目中有出现问题,某些客户的机器偶尔会有,后台取不到前台的数据值. 然开发和测试环境总是不能重现问题.坑爹之处就在于此,不能重现就 ...

  8. ASP.Net MVC开发基础学习笔记:四、校验、AJAX与过滤器

    一.校验 — 表单不是你想提想提就能提 1.1 DataAnnotations(数据注解) 位于 System.ComponentModel.DataAnnotations 命名空间中的特性指定对数据 ...

  9. 为什么google bazel构建工具流行不起来

    作者Jack47 转载请保留作者和原文出处 之前博主写了系列文章Google软件构建工具Bazel原理及使用方法介绍.最近使用了一段时间后,觉得这个东西不是一种通用的构建工具,很难对接到情况复杂的大的 ...

  10. MySQL Dll语句

    标签:MYSQL数据库/DBA/删除数据库表 概述 因为遇到一些事情,从发表上一篇文章到现在中间间隔了好几个月时间:在接下来的时间里会陆续发表关于mysql的一些文章,从基础到优化最后到管理,欢迎关注 ...