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.

Issue with null string comparisons in predicates #2

@carusology

Description

@carusology

If you try to use null as the value for a string comparison in a Where() predicate (and presumably other predicates too), the query provider will throw a NullReferenceException. It looks like this is because it is trying to get the type of the null value.

Here's the stack trace you get when you do it:

System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
    at System.Object.GetType()
    at FSharp.MySqlQueryProvider.QueryTranslator.defaultGetMySqlDBType(TypeSource morP)
    at FSharp.MySqlQueryProvider.QueryTranslator.result$cont@323-4(FSharpFunc`2 getDBType, FSharpFunc`2 getColumnName, FSharpRef`1 columnNameUnique, Context context, Expression e, Unit unitVar)
    at FSharp.MySqlQueryProvider.QueryTranslator.mapFun@304-2.Invoke(Expression e)
    at FSharp.MySqlQueryProvider.Expression.visitor@45.Invoke(Expression e)
    at FSharp.MySqlQueryProvider.Expression.Visitor.Visit(Expression expression)
    at FSharp.MySqlQueryProvider.Expression.map[t](FSharpFunc`2 mapping, Expression expression)
    at FSharp.MySqlQueryProvider.QueryTranslator.bin@314(QueryType queryType, FSharpFunc`2 getDBType, FSharpFunc`2 getColumnName, FSharpFunc`2 getTableName, FSharpRef`1 columnNameUnique, FSharpRef`1 tableAliasIndex, Context context, BinaryExpression e, String text)
    at FSharp.MySqlQueryProvider.QueryTranslator.mapFun@304-2.Invoke(Expression e)
    at FSharp.MySqlQueryProvider.Expression.visitor@45.Invoke(Expression e)
    at FSharp.MySqlQueryProvider.Expression.Visitor.Visit(Expression expression)
    at FSharp.MySqlQueryProvider.Expression.map[t](FSharpFunc`2 mapping, Expression expression)
    at FSharp.MySqlQueryProvider.QueryTranslator.fromWhere@564.Invoke(MethodCallExpression w)
    at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x)
    at FSharp.MySqlQueryProvider.QueryTranslator.mapFun@304-2.Invoke(Expression e)
    at FSharp.MySqlQueryProvider.Expression.visitor@45.Invoke(Expression e)
    at FSharp.MySqlQueryProvider.Expression.Visitor.Visit(Expression expression)
    at FSharp.MySqlQueryProvider.Expression.map[t](FSharpFunc`2 mapping, Expression expression)
    at FSharp.MySqlQueryProvider.QueryTranslator.translate(QueryDialect _queryDialect, QueryType queryType, FSharpOption`1 getDBType, FSharpOption`1 getTableName, FSharpOption`1 getColumnName, Expression expression)
    at FSharp.MySqlQueryProvider.QueryTranslator.translateToCommand(QueryDialect queryDialect, QueryType queryType, FSharpOption`1 getDBType, FSharpOption`1 getTableName, FSharpOption`1 getColumnName, MySqlConnection connection, Expression expression)
    at FSharp.MySqlQueryProvider.MySqlQueryProvider.translate(MySqlConnection con, Expression expression)
    at FSharp.MySqlQueryProvider.MySqlQueryProvider.Execute(Expression expression)
    at FSharp.MySqlQueryProvider.Queryable.QueryProvider.System-Linq-IQueryProvider-Execute[S](Expression expression)
    at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source)

Here's an example of how to get the exception to occur.

String myString = null;
IQueryable<T> queryable = CreateQueryable<T>();

// Throws NullReferenceException
var myFoo = queryable.Where(foo => foo.Property == myString).SingleOrDefault();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions