Cast string as Guid using LinqPad
14,671
Solution 1
Try using the Guid.Parse(string guid)
static method.
var ProductIds = from p in Products
where p.Id == Guid.Parse("F1FE990C-4525-4BFE-9E2C-A7AFFF0DDA1F")
select p;
ProductIds.Dump();
Solution 2
You currently have an assignment, but you want to use a comparison - use ==
instead of =
:
var ProductIds = from p in Products
where p.Id == Guid.Parse("F1FE990C-4525-4BFE-9E2C-A7AFFF0DDA1F")
select p;
Author by
Silverlight Student
Updated on June 22, 2022Comments
-
Silverlight Student almost 2 years
When I run following in the LinqPad
var ProductIds = from p in Products where p.Id = "F1FE990C-4525-4BFE-9E2C-A7AFFF0DDA1F" select p; ProductIds.Dump();
it gives me
Cannot implicitly convert type 'string' to 'System.Guid'
I just don't know how to apply proper cast it to GUid I guess
-
Silverlight Student over 12 yearsAlready tried it but that give me "Cannot implicitly convert type 'System.Guid' to 'bool'" error
-
Silverlight Student over 12 yearsPlease see my response to @Nathan comment
-
Nathan Anderson over 12 yearsMake sure you have
==
between the comparison of p.Id and yourGuid.Parse()
statements, not a single=
. -
Silverlight Student over 12 years:) i must be drunk. Thanks Dude
-
Fischermaen over 12 yearsSo try
Guid.Parse("F1FE990C-4525-4BFE-9E2C-A7AFFF0DDA1F").CompareTo(p.Id) = 0
-
Silverlight Student over 12 yearsSorry for the trouble. I guess I have drinking problem :)
-
Ravi Ram over 9 years@NathanAnderson Using LinqPad I am getting an error:
'System.Guid' does not contain a definition for 'Parse'
-
Nathan Anderson over 9 yearsTry using the constructor that takes a string as an argument. msdn.microsoft.com/en-us/library/96ff78dc%28v=vs.110%29.aspx