Cast string as Guid using LinqPad

风流意气都作罢 提交于 2019-11-30 18:02:37

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

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;

You cannot cast it, you have to parse it like that:

where p.Id = Guid.Parse("F1FE990C-4525-4BFE-9E2C-A7AFFF0DDA1F");

You can also set a variable using:

Guid guid = new Guid ("F1FE990C-4525-4BFE-9E2C-A7AFFF0DDA1F");

Then

var ProductIds = from p in Products
where p.Id == guid
select p;

ProductIds.Dump();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!