Skip to content

Commit

Permalink
Indexes over bool fields are now created with the correct expression
Browse files Browse the repository at this point in the history
  • Loading branch information
lbnascimento committed Jul 13, 2021
1 parent 2db51be commit 0eb1f5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion LiteDB/Client/Database/Collections/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public bool EnsureIndex<K>(string name, Expression<Func<T, K>> keySelector, bool
/// </summary>
private BsonExpression GetIndexExpression<K>(Expression<Func<T, K>> keySelector)
{
var expression = _mapper.GetExpression(keySelector);
var expression = _mapper.GetIndexExpression(keySelector);

if (typeof(K).IsEnumerable() && expression.IsScalar == true)
{
Expand Down
16 changes: 15 additions & 1 deletion LiteDB/Client/Mapper/BsonMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ public BsonExpression GetExpression<T, K>(Expression<Func<T, K>> predicate)
return expr;
}

/// <summary>
/// Resolve LINQ expression into BsonExpression (for index only)
/// </summary>
public BsonExpression GetIndexExpression<T, K>(Expression<Func<T, K>> predicate)
{
var visitor = new LinqExpressionVisitor(this, predicate);

var expr = visitor.Resolve(false);

LOG($"`{predicate.ToString()}` -> `{expr.Source}`", "LINQ");

return expr;
}

#endregion

#region Predefinded Property Resolvers
Expand Down Expand Up @@ -514,7 +528,7 @@ private static void RegisterDbRefItem(BsonMapper mapper, MemberMapper member, IT
}

return m.Deserialize(entity.ForType, doc);

}
else
{
Expand Down

1 comment on commit 0eb1f5f

@lbnascimento
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for #2023

Please sign in to comment.