Cast string as Guid using LinqPad

Silverlight Student picture Silverlight Student · Nov 9, 2011 · Viewed 14.2k times · Source

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

Answer

Nathan Anderson picture Nathan Anderson · Nov 9, 2011

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();