Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
fixed null tests in the linq provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
craiggwilson committed Jun 2, 2010
1 parent 106f724 commit 17e3d57
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
21 changes: 11 additions & 10 deletions source/MongoDB/Linq/Translators/DocumentFormatter.cs
Expand Up @@ -254,7 +254,7 @@ protected override Expression VisitUnary(UnaryExpression u)

private void AddCondition(object value)
{
_scopes.Peek().AddCondition(value);
_scopes.Peek().AddCondition(value ?? NullPlaceHolder.Instance);
}

private void AddCondition(string name, object value)
Expand Down Expand Up @@ -290,15 +290,8 @@ private void PopConditionScope()
doc = (Document)sub;
}

if (scope.Value is MongoDBConstant)
{
switch ((MongoDBConstant)scope.Value)
{
case MongoDBConstant.Null:
doc[scope.Key] = null;
break;
}
}
if (scope.Value is NullPlaceHolder)
doc[scope.Key] = null;
else
doc[scope.Key] = scope.Value;
}
Expand All @@ -324,6 +317,14 @@ private static bool IsBoolean(Expression expression)
return expression.Type == typeof(bool) || expression.Type == typeof(bool?);
}

private class NullPlaceHolder
{
public static readonly NullPlaceHolder Instance = new NullPlaceHolder();

private NullPlaceHolder()
{ }
}

private class Scope
{
public string Key { get; private set; }
Expand Down
12 changes: 0 additions & 12 deletions source/MongoDB/Linq/Translators/MongoDBConstant.cs

This file was deleted.

3 changes: 0 additions & 3 deletions source/MongoDB/Linq/Translators/QueryBinder.cs
Expand Up @@ -47,9 +47,6 @@ protected override Expression VisitBinary(BinaryExpression b)

protected override Expression VisitConstant(ConstantExpression c)
{
if (c.Value == null)
c = Expression.Constant(MongoDBConstant.Null, c.Type);

if (IsCollection(c.Value))
return GetCollectionProjection(c.Value);
return base.VisitConstant(c);
Expand Down
1 change: 0 additions & 1 deletion source/MongoDB/MongoDB.csproj
Expand Up @@ -137,7 +137,6 @@
<Compile Include="Linq\Expressions\MongoExpressionExtensions.cs" />
<Compile Include="Linq\Expressions\MongoExpression.cs" />
<Compile Include="Linq\Translators\ExpressionReplacer.cs" />
<Compile Include="Linq\Translators\MongoDBConstant.cs" />
<Compile Include="MapReduce.cs" />
<Compile Include="Commands\MapReduceCommand.cs" />
<Compile Include="MongoRegexOption.cs" />
Expand Down

0 comments on commit 17e3d57

Please sign in to comment.