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
Projecting bool property through optional nav access with other conditions throws ArgumentException #9275
Comments
This happens in 2.0.0 rtm too. |
Looking at query models
Here |
@maumar - On a different issue, |
Since there is a high chance of needing to release our application with EFCore 2.0, is there a known workaround where it is not necessary to touch the queries? //WORKS
ctx.ChildEntities.Select(child => new
{
child.Id,
IsFieldSet = child.ParentEntity != null && child.ParentEntity.MyValue == true
}).ToList(); Regards |
Try this ctx.ChildEntities.Select(child => new
{
child.Id,
IsFieldSet = child.ParentEntity.MyValue
}).ToList(); You don't need null check when accessing through navigation. EF Core takes care of while expanding navigation. |
I'm well aware of the built-in null check. But as already mentioned, projecting a single bool-value to a view/anonymous object works fine (it would be really critical if not). The error only occours when connecting two or more logical terms in 1:N relations and projecting them. |
Seeing the same thing on an azure hosted SQL server instance. Full framework 4.7 application w/ netstandard2.0 class libraries using EF Core 2.0.0-rtm-26452. Seeing this same behaviour with calling .Any() eg.
The following examples were able to work around the issue
|
…in projection ConditionalExpression requires test to be bool type. When an optional navigation is projected out with other conditions, it coerce everything to nullable bool. When trying to convert to conditional block it fails because test becomes of type nullable bool. The fix is to apply cast before creating ConditionalExpression Resolves #9275
Hi!
We encountered an error in EF Core 2.0 Preview 1 and EF Core 2.0 Preview 2. Since I couldn't find an appropriate short title I'll just describe the problem - feel free to edit the title.
The following model was used to reproduce the error:
DbContext was implemented straightforward with
and
Reproduced with an instance of LocalDB (Version 13.0.2151.0), untested with a "real" SQL-Server instance - shouldn't make a difference, imho.
Wanting to project the Property
ParentEntity.MyValue
to a DTO/ViewModel or even an anonymous type leads to aSystem.ArgumentException: 'Argument must be boolean'
:The funny thing is, selecting the Parent-Property without connecting it to another logical term works fine:
It seems, that the logical operator between the individual expressions causes the problem, since connecting any (senseless) non-constant Expression leads to this ArgumentException:
Tried to debug/fix that on my own, but that is too much expressiontree-madness for me - sorry!
Regards
Peter
cc @bigbabyjesus
The text was updated successfully, but these errors were encountered: