Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
SolvedPrivate

Doing Greater Than or Equal to In LINQ

Posted on 2014-04-01
2
Medium Priority
?
63 Views
Last Modified: 2016-02-15
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
0
Comment
Question by:JoeMiskey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 39969750
Hi JoeMiskey;

You can not use the And or >= operators within a Join clause you can only use Equals therefore you can only test for equality. Also if you need to test more then one field you need to use anonymous type and both anonymous types must have the same property names and must be in the same order so that the system sees them as the same anonymous types. Try the below code snippet to see if it returns the values wanted. Also the way you set the query is that it will return only the p data and not the c data as well so if you need both change the select to this, Select p, c

              
Dim results = From p In PreImportData.AsEnumerable
              Join c In EnhancedACTRulesData
                  On New With { .GroupID = p.Field(Of String)("GroupID"), .SubGroupID = p.Field(Of String)("SubGroupID") } Equals
                     New With { .GroupID = c.Field(Of String)("GroupID"), .SubGroupID = c.Field(Of String)("SubGroupID") }
              Where p.Field(Of DateAndTime)("ServiceStartDate") >= c.Field(Of DateAndTime)("RuleStartDate")
              Select p

Open in new window

0
 

Author Comment

by:JoeMiskey
ID: 39969828
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!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question