-
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
Valid query throws ArgumentException #14991
Comments
I have the same issue... But with the Npgsql.EntityFrameworkCore.PostgreSQL 2.2.0 |
@gsGabriel Are you sure it's the same issue? Is your query and data structure similar to mine? Could you share your reproduce steps? It might help the guys debug and fix this issue. |
Yes, I am sure, the data structure is not exactly the same but it is very close... Follows the sample that resembles my
|
To solve, i broke between two queries, the first to get the posts, on the second query i`m used the posts results to binding a dto. |
I've tested this and can confirm this has been fixed as of EntityFramework 3.0.0, with some changes made to the query. When I ran the original code in 3.0.0 I would get an exception:
After a quick google search I found this issue, so I realized I could change the query in order for it to work: var manualQuery = context.Users.Select(dtoUser => new User.ViewDto
{
Id = dtoUser.Id,
Posts = dtoUser.Posts
.Select(
dtoPost => new Object_205617611___LastComment_Id_Text_UserId
{
__LastComment = dtoPost.Comments.OrderBy(x => x.CreatedAt).LastOrDefault(), // I have added the CreatedAt property
Id = dtoPost.Id,
Text = dtoPost.Text,
UserId = dtoPost.UserId
})
.Select(
dtoLet => new Post.ViewDto
{
Id = dtoLet.Id,
LastComment = (dtoLet.__LastComment == null)
? null
: new Comment.ViewDto
{
Id = dtoLet.__LastComment.Id,
PostId = dtoLet.__LastComment.PostId,
Text = dtoLet.__LastComment.Text
},
Text = dtoLet.Text,
UserId = dtoLet.UserId
})
.ToList()
}).FirstOrDefault(x => x.Id == user.Id); or __LastComment = dtoPost.Comments.OrderByDescending(x => x.CreatedAt).FirstOrDefault(), My thanks to the team and any contributors who might have helped for fixing this issue. |
A valid LINQ query which works over a
List
throws anSystem.ArgumentException
when querying over aDbSet
.The expression is copied from an expression generated by AutoMapper, but the expression should be valid.
Moved from: AutoMapper/AutoMapper#3010
Steps to reproduce
https://github.com/JoasE/AutoMapperRepro
Further technical details
EF Core version: 2.2.2
Database Provider: Microsoft.EntityFrameworkCore.SqlServer 2.2.2
Operating system: Windows 10
IDE: Visual Studio 2017 15.9.6
The text was updated successfully, but these errors were encountered: