Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 548433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:04:41+00:00 2026-05-13T11:04:41+00:00

I am creating some dynamic linq and am having problems with the following exception:

  • 0

I am creating some dynamic linq and am having problems with the following exception:

The binary operator GreaterThanOrEqual
is not defined for the types
‘System.Nullable`1[System.DateTime]’
and ‘System.DateTime’

I get why, because my field type is nullable and Im passing in DateTime.Now essentially.

So in trying to resolve this issue I’ve tried

System.Nullable<DateTime> now;
now = DateTime.Now;

But the resulting type is a non-nullable object and hence still giving me the above exception.

Any suggestions?!

Update: For more clarification the now variable becomes a non-nullable type when it is set rather than staying as a nullable DateTime so the match throws an exception

Update: The actual code can be seen in the CodePlex project:

http://webquarters.codeplex.com/SourceControl/changeset/view/36529#574700

The offending line is ~145

fExp = Expression.GreaterThanOrEqual(fExpLeft, fExpRight);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:04:42+00:00Added an answer on May 13, 2026 at 11:04 am

    The problem here is that the expression library is throwing an exception when given two arguments of mismatched nullability. Here’s a simple repro:

    Expression<Func<DateTime?>> ex1 = ()=>DateTime.Now;
    Expression<Func<DateTime>> ex2 = ()=>DateTime.Now;
    var ex3 = Expression.GreaterThan(ex1.Body, ex2.Body);
    

    It is not clear to me whether this is a bug or not; the rules of C# require that in this scenario, the non-nullable operand is converted to nullable, and the lifted-to-nullable form of the comparison is used. However, the expression tree library is not required to follow the rules of C# because of course the expression tree library can be used to represent C# expressions, Python expressions, JScript expressions, VB expressions and so on; it cannot possibly follow all the rules of every possible language.

    But regardless, this looks like it might be a bug, so I’ll submit it to the expression tree team and see what they say. In the meanwhile, you can easily work around it by defining your own helper method that fixes the operands up. A quick sketch would be:

        static Expression MyGreaterThan(Expression e1, Expression e2)
        {
            if (IsNullableType(e1.Type) && !IsNullableType(e2.Type))
                e2 = Expression.Convert(e2, e1.Type);
            else if (!IsNullableType(e1.Type) && IsNullableType(e2.Type))
                e1 = Expression.Convert(e1, e2.Type);
            return Expression.GreaterThan(e1, e2);
        }
        static bool IsNullableType(Type t)
        {
            return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>);
        }
    

    However, notice that this does not check that e1 and e2’s type differ only in nullability; if you pass in a nullable int and a non-nullable double expression, bad things happen. I leave it as an exercise to implement the better logic that checks whether the two expressions are of type that only differs by nullability.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems with some dynamic elements that I'm creating with Jquery. for(var i
I'm creating a commenting system with knockout.js and I'm having some issues with getting
I am having some trouble creating a experimental 'dynamic' style website. The site is
I'm looking at creating a dynamic linq query where the Where operator will be
I have a question regarding using some features from the System.Linq.Dynamic assembly. I needed
i am creating an application which includes dynamic pages. actually, i created some dynamic
I am generating dynamic PDF reports in PHP and having some issues with links
Im having this weird problem with creating Json dynamically.... for some reason this doesnt
I'm creating a website where I'm doing ajax requests to load some dynamic content
I am looking for some suggestions for creating a User Profile System . I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.