-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
NullReferenceException when materializing a Query type on the right side of a left join #13381
Comments
@dchristensen In this line: modelBuilder.Query<PostView>().ToView("Posts"); is "Posts" the same table that the Post maps to, or is it a database view? If it is a view, how is it defined? |
@ajcvickers In the example I've given it is just referencing the |
@maumar var data = (
from b in ctx.Blogs
join p in ( from post in ctx.Posts
join blog in ctx.Blogs on post.BlogId equals blog.PostId
select new (){post.PostId, post.Title, post.Content, blog.BlogId}
) on b.BlogId equals p.BlogId into pj
// join p in ctx.PostViews on b.BlogId equals p.BlogId into pj //This produces error
// join p in ctx.Posts on b.BlogId equals p.BlogId into pj // This produces correct results
from p in pj.DefaultIfEmpty()
select new { Blog = b, Post = p }).ToList(); |
Now that query types are entity types
cc: @AndriySvyryd |
If mapped to actual view, queries work correctly SELECT [b].[BlogId], [b].[Rating], [b].[Url], [p].[BlogId], [p].[Content], [p].[PostId], [p].[Title]
FROM [Blogs] AS [b]
LEFT JOIN [PostView] AS [p] ON [b].[BlogId] = [p].[BlogId] Generated SQL for 2nd case SELECT [b].[BlogId], [b].[Rating], [b].[Url], [t].[PostId], [t].[Title], [t].[Content], [t].[BlogId0] AS [BlogId]
FROM [Blogs] AS [b]
LEFT JOIN (
SELECT [p].[PostId], [p].[BlogId], [p].[Content], [p].[Title], [b0].[BlogId] AS [BlogId0], [b0].[Rating], [b0].[Url]
FROM [Posts] AS [p]
INNER JOIN [Blogs] AS [b0] ON [p].[BlogId] = [b0].[BlogId]
) AS [t] ON [b].[BlogId] = [t].[BlogId0] |
Split out mapping issue to #19257 |
…ng a Query type on the right side of a left join Issue has been fixed in earlier checkin. Resolves #13381
…ng a Query type on the right side of a left join Issue has been fixed in earlier checkin. Resolves #13381
…ng a Query type on the right side of a left join Issue has been fixed in earlier checkin. Resolves #13381
…ng a Query type on the right side of a left join Issue has been fixed in earlier checkin. Resolves #13381
…ng a Query type on the right side of a left join Issue has been fixed in earlier checkin. Resolves #13381
…ng a Query type on the right side of a left join Issue has been fixed in earlier checkin. Resolves #13381
Forgive my ignorance, but after this fix has been pushed, how long should we expect before it's available in an official patch or release and how can I tell in which release it's included? |
@davidbrinton The milestone. In this case the milestone is 5.0.0. This will be updated to indicate the preview it is in when we cut that preview--most likely preview 7 at this point. |
When executing a query where a Query Type is being used on the right side of a left outer join, when there is no row that matches the left side EF Core attempts to construct an object and map
NULL
to the properties, which fails when the Query Type model has non-nullable types. Executing the same query with an Entity Type correctly produces anull
value instead of attempting to construct the object.Steps to reproduce
In this following sample I would expect
data[0].Post
to benull
instead of throwing the exception.Further technical details
EF Core version: 2.1.3
Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Operating system: Windows 10 17134
IDE: Visual Studio 2017 15.8
The text was updated successfully, but these errors were encountered: