This repository was archived by the owner on Feb 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
Add support for 'HasValue' and 'Value' for properties of type Nullable<T> #12
Copy link
Copy link
Open
Labels
Description
Background
If you attempt to use the HasValue or Value on a queryable's property that is an instance of Nullable<T> within a LINQ expression, you will get an exception with the message "The member '[Has]Value' is not supported".
Here's an example.
Given the following data model...
public class Fake : ImmutableBase<Fake> {
public Nullable<DateTime> OptionalDate { get; }
public Fake(Nullable<DateTime> optionalDate = null) {
this.OptionalDate = optionalDate;
}
}... this code will throw exceptions with the aforementioned message.
IQueryable<Fake> queryable = ...;
var nonNullDates =
queryable
.Where(model => model.OptionalDate.HasValue)
.Select(model => model.OptionalDate.Value)
.ToImmutableList();Task
Add support for HasValue and Value for properties of type Nullable<TValueType> that exist on a class being queried via a FSharp.MySqlQueryProvider. Presumably "HasValue" property should be converted to a MySQL-based "IS NULL" check, and "Value" property should be a ignored / passed through.
Stack Trace
Error Message:
System.Exception : The member 'HasValue' is not supported
Stack Trace:
at FSharp.MySqlQueryProvider.QueryTranslator.result@807-5.Invoke(String message)
at FSharp.MySqlQueryProvider.QueryTranslator.mapFun@306-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@575.Invoke(MethodCallExpression w)
at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x)
at FSharp.MySqlQueryProvider.QueryTranslator.mapFun@306-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.f@1[T](Query`1 this, Unit unitVar0)
at FSharp.MySqlQueryProvider.Queryable.Query`1.getEnumerable()
at FSharp.MySqlQueryProvider.Queryable.Query`1.System-Collections-Generic-IEnumerable`1-GetEnumerator()