我正在使用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'的值转换为'String'。

我对Linq非常陌生。有人可以解释什么地方不对吗?

谢谢!

最佳答案

Dim queryEmployeeSites = _
    From employeesites In rdc.EmployeeSites _
    Where _
    employeesites.SiteId.ToString().Equals("86086EC5-567A-46B3-8DFC-E624F9B0324B") _
    Select employeesites

For Each employeesites As EmployeeSite In queryEmployeeSites
    employeesites.SiteId = Nothing
Next

rdc.SubmitChanges()

而是应调用ToString()起作用,也最好将Equals用于字符串相等性,或使用String.Compare

10-01 03:02