This project is read-only.

IContentQuery and (Nullable) DateTime?

Topics: Core, General, Troubleshooting, Writing modules
Nov 7, 2012 at 11:15 PM
Edited Nov 7, 2012 at 11:16 PM

I am attempting to use the PredicateBuilder to create dynamic filters on a content query.  If one of the properties on my model is a nullable property, it blows up with an error message.

I get this error message:

could not resolve property: DateIn.HasValue

when I run this query:


.Where<TestPartRecord>(r =>
r.DateIn.HasValue &&
r.DateIn.Value >= System.DateTime.Parse("11/01/2012")
public class TestPartRecord : ContentPartRecord
  public virtual DateTime? DateIn { get; set; }

Does anyone know how to query using the .HasValue and .Value properties on a nullable type/property?

Nov 8, 2012 at 2:50 AM

I'm suspecting it's nHibernate that has no idea what to do with that. Try to do it differently.

Nov 14, 2012 at 5:35 PM
Edited Nov 14, 2012 at 5:36 PM

In case anyone was/is nHibernate and I was able to work around the issue by calling Expression.Convert on the nullable type from within the PredicateBuilder instead of calling the HasValue and Value properties of the nullable type.

Basically I used this:

Expression.GreaterThan(Expression.Convert(expL, expR.Type), expR)

Instead of this:

Expression.AndAlso(MemberExpression.Property(expL, "HasValue"), Expression.GreaterThan(MemberExpression.Property(expL, "Value"), expR)) :