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

Issue with null string comparisons in predicates #2

Open
carusology opened this issue Dec 28, 2016 · 0 comments
Open

Issue with null string comparisons in predicates #2

carusology opened this issue Dec 28, 2016 · 0 comments
Labels

Comments

@carusology
Copy link
Contributor

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 [email protected](Expression e)
    at [email protected](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 [email protected](Expression e)
    at [email protected](Expression e)
    at FSharp.MySqlQueryProvider.Expression.Visitor.Visit(Expression expression)
    at FSharp.MySqlQueryProvider.Expression.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 [email protected](Expression e)
    at [email protected](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();
@carusology carusology added the bug label Dec 28, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant