-
Notifications
You must be signed in to change notification settings - Fork 6
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
[Feature request] Simplify null == null and null != null #12
Comments
Basically this should already happen... It says that in conditional expression, visit also the test-part here In your case, the test part, I expect to be a And then when it's a true, it should be replaced via this rule So why is it not working... Maybe there is some problem with comparing null-expression to null-expression, e.g. can they differ the type level information? Or are the Left and Right part of your BinaryExpression something else than Constants? Like "null"s here? |
Thanks for the information and extensive reply. I will try and see if I can get more information about this tomorrow. The IIF was probably from the ToString representation of the expression in debug mode will try and see if I can se the real ExpressionTypes instead. |
I think the proper special case here, is that I think it'd be a reasonable addition. The reason I'm kind of cautious to create these are that if someone compares more complex objects than primitive types, like your PeriodData here, the likelihood of someone adding a side-effect to any cast or comparison increases, and eliminating these in LINQ will kill the side-effects away. |
I think that sounds like a great option. To minimize the effect of this, maybe add some kind of settings parameter, so the user can configure if the new check is desired? This would be more work of course, but it would also make sure that the new check is not used until it is op-in, and thus it would not break any existing code-bases. In the meantime I did this: private static Expression<Func<Subject, EducationEvent, bool, PeriodData, MyListDTO>> BaseExpression =>
(subject, educationEvent, usePeriodData, periodData) => new MyListDTO
{
FolkbokforingskommunName = usePeriodData ? periodData.Municipality.Namn : subject.Folkbokforingskommun.Name,
}; And I set the |
Description
I'm buildning a library of Select Expressions for our product and have found that I would like to do something like this:
This is then Invoked and Expanded with LinqKit and passed down to Entity Framework.
Obviously this does not work since null is not allowed for non-static parameters (even static?) but I have looked at the expression tree and this does create an IIF condition that looks like this:
Would it be much work to eliminate the IIF and just replace it with the correct branching?
The text was updated successfully, but these errors were encountered: