-
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
Argument types don't match for queries projecting conditional expression with anonymous type result #8315
Comments
Tried upgrading to 1.1.1 to see if it would fix the issue but it didn't. |
@sethen - Please share your DbContext & model classes esp. Analysis, Comment, Game, Reward, Matchup. |
Sorry it took so long for me to respond, I have been busy. Here are the files you requested. |
@sethen - Thank you for the files. There were few missing pieces but I was able to fill in the blanks and get a repro. I will investigate further to find the root cause. |
Offending query:
Classes
Optional nav. |
Assigning to @maumar |
…itional expression with anonymous type result Problem was that when translating anonymous type we change the expression type from the anonymous type to Expression[]. In case of conditional expression, if the second result is null constant, it's type stays the same, and when we try to update ConditionalExpression, type mismatch is thrown. Fix is to recognize the pattern and force client eval for this case, since we cant map objects of type Expression[] anyway.
…itional expression with anonymous type result Initial problem was that when translating anonymous type we change the expression type from the anonymous type to Expression[]. In case of conditional expression, if the second result is null constant, it's type stays the same, and when we try to update ConditionalExpression, type mismatch is thrown. However, even if the types are compensated for, we can't translate NewExpression to SQL, apart from it being used in comparison (e.g. in composite key join scenarios) Fix is to recognize the pattern and force client eval. Also fixes small bug around alias generation.
…itional expression with anonymous type result Initial problem was that when translating anonymous type we change the expression type from the anonymous type to Expression[]. In case of conditional expression, if the second result is null constant, it's type stays the same, and when we try to update ConditionalExpression, type mismatch is thrown. However, even if the types are compensated for, we can't translate NewExpression to SQL, apart from it being used in comparison (e.g. in composite key join scenarios) Fix is to recognize the pattern and force client eval. Also fixes small bug around alias generation.
…itional expression with anonymous type result Initial problem was that when translating anonymous type we change the expression type from the anonymous type to Expression[]. In case of conditional expression, if the second result is null constant, it's type stays the same, and when we try to update ConditionalExpression, type mismatch is thrown. However, even if the types are compensated for, we can't translate NewExpression to SQL, apart from it being used in comparison (e.g. in composite key join scenarios) Fix is to recognize the pattern and force client eval. Also fixes small bug around alias generation.
Fixed in 521feb5 |
Thanks a lot, a few questions:
|
@Eilon might have some info about the dates. In the meantime you should be able to do: var analysis = db.Analysis.Select(a => new
{
id = a.AnalysisId,
(int?)reward = a.Reward.UserId
})
.ToList()
.Select(a => new { a.id, reward = a.reward != null ? new { user_id = reward } : null } Basically, you can project the columns that you need in the final result (EF Core will do the null protection logic for you) and then do another Select(...) on the client to convert the flat results into desirable shape. |
2.0.0 preview 2 isn't too far out - next month I think. Or you can grab the nightly builds from https://dotnet.myget.org/gallery/aspnetcore-dev. |
@maumar Thanks for this... I found another way around that seems to fit my use case pretty nicely until this is ready for production. This will fetch the reward and ignore if it's null:
Not ideal, but until 2.0.0 is ready -- it works. |
I am using a query in my repository which you can view at this gist: https://gist.github.com/sethen/c1f3cb54e50eb36b696a1f4d79d1670c#file-gistfile1-txt-L23 which is similar to the query I found in issue #5522 -- unfortunately I am still getting the same error. Here is my stack trace:
Essentially I just want to be able to work with nullable properties on my models in a sane way. The issue referenced said that this was fixed but I have tried many ways to get around this and nothing is working.
Further technical details
EF Core version: (found in project.json or packages.config) 1.1.0
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Operating system: macOS Sierra
IDE: VSCode
The text was updated successfully, but these errors were encountered: