Skip to content
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

Null in Queriers #1

Closed
Reyhanejaffari opened this issue Feb 7, 2018 · 5 comments
Closed

Null in Queriers #1

Reyhanejaffari opened this issue Feb 7, 2018 · 5 comments

Comments

@Reyhanejaffari
Copy link

this query does not work
organizationalRoles = organizationalRoles.Where("(Parent!=null ? parent.Name:Title)");
how did you handle null values in code

@Reyhanejaffari
Copy link
Author

i add
if (_keywords.TryGetValue(_token.Text, out value))
{
var type = value as Type;
if (type != null) return ParseTypeAccess(type);
if (value == NullLiteral)
{
Expression expr = value as Expression;
NextToken();
return expr;
}
if ((string)value == KeywordIt) return ParseIt();
if ((string)value == KeywordOuterIt) return ParseOuterIt();
if ((string)value == KeywordIif) return ParseIif();
if ((string)value == KeywordNew) return ParseNew();
NextToken();
return null;
}
in Expression ParseIdentifier() and it works.
is this code true?

@umutozel
Copy link
Owner

umutozel commented Mar 8, 2018

Sorry for the late reply, I missed the notification I believe.

You should use a comparison in your expression, it should work with that, I am adding a new unit test right now;

        Assert.Equal(
            _query.Where(o => (o.Id == 5 ? 1 : 0) != 0),
            _query.Where("(Id == 5 ? 1 : 0) != 0")
        );

and it's working.

I believe your code should be like this;

organizationalRoles.Where("(Parent!=null ? parent.Name:Title) != null");

@umutozel umutozel closed this as completed Mar 8, 2018
@gbreen12
Copy link

gbreen12 commented Nov 4, 2019

I'm trying to do something similar and it doesn't seem to work:

query.OrderBy($"{ob.Field}==null")

Any ideas?

@gbreen12
Copy link

gbreen12 commented Nov 5, 2019

Looks like I just needed to change it to:

query.OrderBy($"x => !x.{ob.Field}.HasValue")

@umutozel
Copy link
Owner

umutozel commented Nov 6, 2019

@gbreen12 first one should work, I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants