Linq - “System.Guid”类型的值无法转换为“字符串”
我正在使用 Linqer 将 SQL 转换为 Linq:
Update EmployeeSite SET SiteId = Null
WHERE SiteId = '86086EC5-567A-46B3-8DFC-E624F9B0324B'
转换为:
Dim queryEmployeeSites = _
From employeesites In rdc.EmployeeSites _
Where _
CStr(employeesites.SiteId) = "86086EC5-567A-46B3-8DFC-E624F9B0324B" _
Select employeesites
For Each employeesites As EmployeeSite In queryEmployeeSites
employeesites.SiteId = Nothing
Next
rdc.SubmitChanges()
但是当我尝试运行 Linq 代码时,我收到错误消息:
编译表达式错误:编译表达式错误:“System.Guid”类型的值无法转换为'细绳'。
我对 Linq 很陌生。有人可以解释一下出了什么问题吗?
谢谢!
I'm using Linqer to convert SQL to Linq:
Update EmployeeSite SET SiteId = Null
WHERE SiteId = '86086EC5-567A-46B3-8DFC-E624F9B0324B'
Gets translated into:
Dim queryEmployeeSites = _
From employeesites In rdc.EmployeeSites _
Where _
CStr(employeesites.SiteId) = "86086EC5-567A-46B3-8DFC-E624F9B0324B" _
Select employeesites
For Each employeesites As EmployeeSite In queryEmployeeSites
employeesites.SiteId = Nothing
Next
rdc.SubmitChanges()
But when I try to run the Linq code I get the error message:
Error Compiling Expression: Error Compiling Expression: Value of type 'System.Guid' cannot be converted to 'String'.
I am very new to Linq. Can someone please explain what is wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
CStr(employeesites.SiteId)
替换为employeesites.SiteId.ToString()
,但最好是相反比较这样您就不会遇到大小写不同的问题等
You can replace
CStr(employeesites.SiteId)
withemployeesites.SiteId.ToString()
, but the best is to compare the other way aroundThis way you don't run into issues with different capitalization, etc.
调用
ToString()
应该可以,而且最好使用Equals
来实现字符串相等,或者使用String.Compare
。Calling
ToString()
instead should work, also it's better to useEquals
for String Equality, or useString.Compare
.