Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Add support for null in Contains queries #17

@carusology

Description

@carusology

Right now we do not support "Contains" queries when one of the items in the collection is null. Here's a query as an example:

var hasNull = new List<string> { "Foo", "Bar", null };

var result = 
    queryable
        .Where(someEntity => hasNull.Contains(someEntity.NullableString))
        .ToImmutableList();

This query will need to be rewritten from a traditional NullableString IN ("Foo", "Bar") clause to a disjunctive query including both the non-null values and the null value, like so: NullableString IN ("Foo", "Bar") OR NullableString IS NULL. However, at this point it does not yet get to that far. Instead, we get the following stack trace:

Error Message:
 System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
   at System.Object.GetType()
   at Invio.QueryProvider.MySql.QueryTranslatorUtilities.unwrapValue(Object value)
   at Invio.QueryProvider.MySql.QueryTranslatorUtilities.valueToQueryAndParam[a](Int32 columnIndex, DBType`1 dbType, Object value)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.map@74.DoMoveNext(b& curr)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at Invio.QueryProvider.MySql.QueryTranslator.result$cont@722-3(FSharpFunc`2 getDBType, FSharpFunc`2 getColumnName, FSharpFunc`2 getTableName, FSharpRef`1 columnNameUnique, FSharpRef`1 tableAliasIndex, Context context, IEnumerable enumerableObject, FSharpList`1 args, Unit unitVar)
   at Invio.QueryProvider.MySql.QueryTranslator.result$cont@694(FSharpFunc`2 getDBType, FSharpFunc`2 getColumnName, FSharpFunc`2 getTableName, FSharpRef`1 columnNameUnique, FSharpRef`1 tableAliasIndex, Context context, MethodCallExpression m, Unit unitVar)
   at [email protected](Expression e)
   at [email protected](Expression e)
   at Invio.QueryProvider.ExpressionHelper.Visitor.Visit(Expression expression)
   at Invio.QueryProvider.ExpressionHelper.map[t](FSharpFunc`2 mapping, Expression expression)
   at [email protected](MethodCallExpression w)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x)
   at Invio.QueryProvider.MySql.QueryTranslator.result$cont@360-4(FSharpFunc`2 getDBType, FSharpFunc`2 getColumnName, FSharpFunc`2 getTableName, FSharpRef`1 columnNameUnique, FSharpRef`1 tableAliasIndex, Context context, FSharpOption`1 linqChain, Unit unitVar)
   at [email protected](Expression e)
   at [email protected](Expression e)
   at Invio.QueryProvider.ExpressionHelper.Visitor.Visit(Expression expression)
   at Invio.QueryProvider.ExpressionHelper.map[t](FSharpFunc`2 mapping, Expression expression)
   at Invio.QueryProvider.MySql.QueryTranslator.translateToStatement(FSharpOption`1 getDBType, FSharpOption`1 getTableName, FSharpOption`1 getColumnName, Expression expression)
   at Invio.QueryProvider.MySql.MySqlQueryProvider.PrepareEnumerable[T](Expression expression)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions