Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Operator '&&' cannot be applied to operands of type 'System.Guid' and 'int?

Posted on 2009-02-17
Medium Priority
Last Modified: 2013-12-17
I am trying to build a LINQ query using a GUID in a where clause and keep getting this error message.  Why can you not search using a GUID as a key?

Here is my code.
var patientlookup = from MPIREC in db.MPIs
                                                    where recordMPI.MPI1 = initGuid &&------squiggle under initGuid
                                                    recordMPI.NPI = ecDoctor.NPI
                                                    select new { MPIREC };

Open in new window

Question by:kwh3856
  • 4
  • 2
LVL 21

Expert Comment

ID: 23667041
I am assuming that recordMPI.MPI1 is an int, and initGuid is a GUID.  They are not the same kind of variable, so you cannot compare them.  You will have to convert one to the other before you compare.
LVL 21

Accepted Solution

naspinski earned 2000 total points
ID: 23667066
scratch my last comment.

Once again, you are using '=' instead of '=='

You are trying to set the variables, not compare them

Author Comment

ID: 23667071
That is what I first thought when I read the error message but I checked by table and MPI has a field type of uniquie.  When I hover over .MPI1 it displays the message GuidMPI.MPI1.  Based on that I assume it is a GUID type.
When I created the initGuid, this is the code I used which initializes the variable as Guid.  I know I am missing something here but it is just not jumping out at me.  Here the code I use to create initGuid.
Could there be something else?

public static Guid initGuid
return Guid.NewGuid();
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database


Author Comment

ID: 23667075
ooh...i will try that

Author Comment

ID: 23667084
ok.  When I did that, now I get
 '&&' cannot be applied to operands of type 'bool' and 'int?'
I thought when I got that error message I am supposed to used the single =
should i use .equals???

Author Closing Comment

ID: 31548151
You were right.  I just did not see it.  Here was the correct code.

var patientlookup = from MPIREC in db.MPIs
                                                    where recordMPI.MPI1 == initGuid &&
                                                    recordMPI.NPI == Convert.ToInt32(ecDoctor.NPI)
                                                    select new { MPIREC };

Thanks once again.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

580 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