在 vb.net 程序中指定有效谓词时遇到问题

Having problem with specifying a valid predicate in vb.net program

我目前正在支持试图迁移到另一个域的旧 vb.net 应用程序。 当 运行 在旧域上时,它工作得很好,但是当 运行 .exe 在新域中时,会弹出此错误:

System.ArgumentException: You must specify a valid predicate for filtering the results. Parameter name: predicate at System.Data.Objects.ObjectQuery`1.Where(String predicate, ObjectParameter[] parameters) at COOP_Incentive.frmEmployeeMaster.LoadDefaultData() in C:\Users\username\Desktop\CBVS For new_domain\COOP Incentive\Forms\Setup - Employee Master\frmEmployeeMaster.vb:line 78
at COOP_Incentive.frmEmployeeMaster.frmEmployeeMaster_Load(Object sender, EventArgs e) in C:\Users\username\Desktop\CBVS For new_domain\COOP Incentive\Forms\Setup - Employee Master\frmEmployeeMaster.vb:line 329 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.SetVisibleCore(Boolean value) at System.Windows.Forms.Form.SetVisibleCore(Boolean value) at WeifenLuo.WinFormsUI.Docking.DockContentHandler.SetVisible() at WeifenLuo.WinFormsUI.Docking.DockPane.set_ActiveContent(IDockContent value) at WeifenLuo.WinFormsUI.Docking.DockContentHandler.Activate() at WeifenLuo.WinFormsUI.Docking.DockContentHandler.Show(DockPanel dockPanel, DockState dockState) at COOP_Incentive.frmEmployeeMaster.Show(DockPanel dockpanel) in C:\Users\username\Desktop\CBVS For new_domain\COOP Incentive\Forms\Setup - Employee Master\frmEmployeeMaster.vb:line 356 at COOP_Incentive.frmMenu.cmdEmployeeMaster_Click(Object sender, EventArgs e) in C:\Users\username\Desktop\CBVS For new_domain\COOP Incentive\Forms\MainForms\frmMenu.vb:line 26 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

根据错误消息,这是它所指的代码:

cboBusinessUnit.DataSource = (From r In DefaultBusinessUnitSet.Where(filter).Execute(MergeOption.PreserveChanges) _
                           Order By r.BussinessCode _
                           Select New With {.id = r.BussinessCode, .text = r.BussinessName}).ToList()

这是“Where”部分中的过滤器变量:

Dim filter As String = String.Join(" or ", (From result In SessionUtil.AllowedEmployerCodes _
                                               Let c = " it.BussinessCode='" + result + "' " _
                                               Select c).ToArray())

我不熟悉这种错误,我该如何解决这个问题?

过滤器字符串很可能在登陆时包含一些使其无效的内容。我建议在抛出错误时显示过滤器值。例如,您的雇主代码之一可能包含撇号。在这种情况下,您需要用替换来包装结果,例如替换(结果,“'”,“''”)。

检查过滤器变量时,它没有反映任何数据。我需要检查 SessionUtil.AllowedEmployerCodes 的所有引用,发现在登录期间,它将基于您的 SID。我忽略了一个 table,我应该在其中将我的 SID 从旧域更新到新域。它成功了!