kwh3856
asked on
Operator '&&' cannot be applied to operands of type 'System.Guid' and 'int?
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.
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 };
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
naspinski,
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
{
get
{
return Guid.NewGuid();
}
}
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
{
get
{
return Guid.NewGuid();
}
}
ASKER
ooh...i will try that
ASKER
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???
'&&' 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???
ASKER
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.N PI)
select new { MPIREC };
Thanks once again.
var patientlookup = from MPIREC in db.MPIs
where recordMPI.MPI1 == initGuid &&
recordMPI.NPI == Convert.ToInt32(ecDoctor.N
select new { MPIREC };
Thanks once again.