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

LINQ conditional support #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,6 @@ $RECYCLE.BIN/

# Mac desktop service store files
.DS_Store

# Jetbrains Rider
.idea
19 changes: 19 additions & 0 deletions src/ArangoDB.Client.Test/Linq/SimpleQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ public void FromWithSelect()

Assert.Equal("for `p` in `Person` return `p`", query.GetQueryData().Query.RemoveSpaces());
}

[Fact]
public void FromWithSelectNewTernary()
{
var db = DatabaseGenerator.Get();
var query = from p in db.Query<Person>()
select new Person
{
Fullname = p.Age > 10 ? p.Fullname : "",
Outfit = p.Age < 10 ? p.Outfit : null
};
var queryText = query.GetQueryData().Query.RemoveSpaces();
Assert.Equal(
@"for `p` in `Person`
return {
`Fullname` : ( `p`.`Age` > @P1 ) ? `p`.`Fullname` : @P2 ,
`Outfit` : ( `p`.`Age` < @P3 ) ? `p`.`Outfit` : @P4
}".RemoveSpaces(), queryText);
}

[Fact]
public void FromWithSelectNew()
Expand Down
10 changes: 10 additions & 0 deletions src/ArangoDB.Client/Query/ArangoExpressionTreeVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ public ArangoExpressionTreeVisitor(ArangoModelVisitor modelVisitor)
this.ModelVisitor = modelVisitor;
}

protected override Expression VisitConditional(ConditionalExpression expression)
{
VisitBinary(expression.Test as BinaryExpression);
ModelVisitor.QueryText.Append(" ? ");
Visit(expression.IfTrue);
ModelVisitor.QueryText.Append(" : ");
Visit(expression.IfFalse);
return expression;
}

protected override Expression VisitMethodCall(MethodCallExpression expression)
{
if (expression.Method.Name == "As")
Expand Down