Link to home
Start Free TrialLog in
Avatar of JoeMiskey
JoeMiskeyFlag for United States of America

asked on

Doing Greater Than or Equal to In LINQ

I am trying to create a LINQ expression in VB.NET.  For some reason, I cannot get it to work.

Here are the references I have at the top of my class:
Imports System.Data.SqlClient
Imports System.IO
Imports System.Text
Imports System.Linq

Open in new window

Here is the LINQ statement I have in one of my procedures:
        Dim results = From p In PreImportData.AsEnumerable
                        Join c In EnhancedACTRulesData
                        On p.Field(Of String)("GroupID") Equals c.Field(Of String)("GroupID") _
                        And p.Field(Of String)("SubGroupID") Equals c.Field(Of String)("SubGroupID") _
                        And p.Field(Of DateAndTime)("ServiceStartDate") >= c.Field(Of DateAndTime)("RuleStartDate")
                        Select p

Open in new window

It does not like the ">=" in my last condition.

If I remove this last condition, or change the ">=" to "Equals", it does not return any syntax errors.

I have searched a lot of code examples on the web, and see lots of uses of "=", ">=", and "<=", but it seems I cannot use any of those.  The only one it seems to like is "Equals".

Any idea why this is?  Am I missing something?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JoeMiskey

ASKER

I cannot believe I did that!  I had been staring at it for so long, I thought I was working in the WHERE clause, and not the JOIN clause (I had gone back-and-forth on the code a few times).

I changed it to this, and it worked perfectly.
        Dim results = From p In PreImportData.AsEnumerable
                        Join c In EnhancedACTRulesData
                        On p.Field(Of String)("GroupID") Equals c.Field(Of String)("GroupID") _
                        And p.Field(Of String)("SubGroupID") Equals c.Field(Of String)("SubGroupID") _
                        Where p.Field(Of Date)("ServiceStartDate") >= c.Field(Of Date)("RuleStartDate")
                        Select p

Open in new window

Thanks for finding my boneheaded error!