Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra join in query for value objects in Entity framework Core #20541

Closed
MohammadAkbari opened this issue Apr 6, 2020 · 1 comment
Closed

Comments

@MohammadAkbari
Copy link

In Entity Framework core 3.1.3, I have used the value object feature. In the query side, the problem is an extra left join exists in TSql. This extra join results problems in terms of performance.

Entities

public class Student
{
	public int Id { get; set; }
	public string Name { get; set; }
	public Address Address { get; set; }
}
public class Address
{
	public string Street { get; set; }
	public string City { get; set; }
	public string ZipCode { get; set; }
}

DbContext

public class ApplicationDbContext : DbContext
{
	public DbSet<Student> Students { get; set; }

	protected override void OnModelCreating(ModelBuilder builder)
	{
		builder.Entity<Student>().OwnsOne(e => e.Address);
		base.OnModelCreating(builder);
	}
}

Entity framework query

var list = _dbContext.Students.ToList();

Generated SQL

SELECT [s].[Id], [s].[Name], [t].[Id], [t].[Address_City], 
	   [t].[Address_Street], [t].[Address_ZipCode]
FROM [Students] AS [s]
LEFT JOIN (
	SELECT [s0].[Id], [s0].[Address_City], 
		   [s0].[Address_Street], [s0].[Address_ZipCode]
	FROM [Students] AS [s0]
	WHERE [s0].[Address_ZipCode] IS NOT NULL OR 
		  ([s0].[Address_Street] IS NOT NULL OR 
		  [s0].[Address_City] IS NOT NULL)
) AS [t] ON [s].[Id] = [t].[Id]

Further technical details

EF Core version:
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1.1
Operating system: Windows 10
IDE: Visual Studio 2019 16.3

@ajcvickers
Copy link
Member

Duplicate of #18299

@ajcvickers ajcvickers marked this as a duplicate of #18299 Apr 6, 2020
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants