LINQ 编译查询不会执行 - ArgumentNulException 未处理
我是第一次测试编译查询。
我当前的查询是:
Shared compiledLatestDate As Func(Of RackJobbingDataDataContext, ArtikelInfoParameters, List(Of VerdelingPlanning)) = _
CompiledQuery.Compile(Of RackJobbingDataDataContext, ArtikelInfoParameters, List(Of VerdelingPlanning))( _
Function(db As RackJobbingDataDataContext, param As ArtikelInfoParameters) _
(From verdplan As VerdelingPlanning In db.VerdelingPlannings _
Join artPlan As ArtikelPlanning In db.ArtikelPlannings _
On artPlan.VerdelingPlanningID Equals verdplan.VerdelingPlanningID _
Join levDet As LeveringDetail In db.LeveringDetails _
On levDet.ArtikelPlanningID Equals artPlan.ArtikelPlanningID _
Join lev As Levering In db.Leverings _
On lev.LeveringID Equals levDet.LeveringID _
Where artPlan.ArtikelID.Equals(param.artId) _
And lev.WinkelID.Equals(param.winkId) _
And Not levDet.PlanningAantal.Equals(Nothing) _
And levDet.PlanningAantal <> 0 _
And verdplan.Datum < param.datumVerdeling _
Order By verdplan.Datum Descending _
Select levDet))
但我收到一个 ArgumentNulException 未处理。
建议 LINQ 查询添加具有所需参数的对象,因此这就是类:
Public Class ArtikelInfoParameters
Private _wkId As Guid
Private _artId As Guid
Private _datumVerdeling As DateTime
Public Sub New(ByVal artId As Guid, ByVal winkId As Guid, ByVal datumVerdeling As DateTime)
_artId = artId
_wkId = winkId
_datumVerdeling = datumVerdeling
End Sub
Public Property artId As Guid
Get
Return _artId
End Get
Set(ByVal value As Guid)
_artId = value
End Set
End Property
Public Property winkId As Guid
Get
Return _wkId
End Get
Set(ByVal value As Guid)
_wkId = value
End Set
End Property
Public Property datumVerdeling As DateTime
Get
Return _datumVerdeling
End Get
Set(ByVal value As DateTime)
_datumVerdeling = value
End Set
End Property
End Class
为了完整起见,这是我收到的错误。
bij System.Data.Linq.SqlClient.SqlJoin.set_Left(SqlSource value)
bij System.Data.Linq.SqlClient.SqlMultiplexer.Visitor.VisitMultiset(SqlSubSelect sms)
bij System.Data.Linq.SqlClient.SqlVisitor.VisitSubSelect(SqlSubSelect ss)
bij System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
bij System.Data.Linq.SqlClient.SqlVisitor.VisitExpression(SqlExpression exp)
bij System.Data.Linq.SqlClient.SqlMultiplexer.Visitor.VisitSelect(SqlSelect select)
bij System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
bij System.Data.Linq.SqlClient.SqlProvider.BuildQuery(ResultShape resultShape, Type resultType, SqlNode node, ReadOnlyCollection`1 parentParameters, SqlNodeAnnotations annotations)
bij System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations)
bij System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Compile(Expression query)
bij System.Data.Linq.CompiledQuery.ExecuteQuery(DataContext context, Object[] args)
bij System.Data.Linq.CompiledQuery.Invoke[TArg0,TArg1,TResult](TArg0 arg0, TArg1 arg1)
bij RackJobbing.UI.ucArtikelInfo.getLatestDate(Guid artikelId) in D:\EasySolutions\TFS\Provoost\Development\RackJobbing\RackJobbing.UI\Snelinvoer\Verdeling\ucArtikelInfo.vb:regel 69
bij RackJobbing.UI.ucArtikelInfo.UpdateInfo() in D:\EasySolutions\TFS\Provoost\Development\RackJobbing\RackJobbing.UI\Snelinvoer\Verdeling\ucArtikelInfo.vb:regel 111
bij RackJobbing.UI.frmPrePlanning.UcVerdeling1_ArtikelWinkelChanged() in D:\EasySolutions\TFS\Provoost\Development\RackJobbing\RackJobbing.UI\Snelinvoer\Verdeling\frmPrePlanning.vb:regel 280
bij RackJobbing.UI.ucVerdeling.grdVerdeling_EnterCell(Object sender, EventArgs e) in D:\EasySolutions\TFS\Provoost\Development\RackJobbing\RackJobbing.UI\Snelinvoer\Verdeling\ucVerdeling.vb:regel 339
bij C1.Win.C1FlexGrid.C1FlexGridBase.OnEnterCell(EventArgs e)
bij C1.Win.C1FlexGrid.C1FlexGridBase.a9()
bij C1.Win.C1FlexGrid.C1FlexGridBase.OnGridChanged(Object sender, GridChangedEventArgs e)
bij C1.Win.C1FlexGrid.C1FlexGrid.OnGridChanged(Object sender, GridChangedEventArgs e)
bij C1.Win.C1FlexGrid.t.bc(GridChangedTypeEnum A_0, Int32 A_1, Int32 A_2, Int32 A_3, Int32 A_4)
bij C1.Win.C1FlexGrid.t.bn(GridChangedTypeEnum A_0)
bij C1.Win.C1FlexGrid.p.n(C1FlexGridBase A_0, CellRange A_1, Boolean A_2)
bij C1.Win.C1FlexGrid.C1FlexGridBase.Select(CellRange rg, Boolean show)
bij C1.Win.C1FlexGrid.ab.o(MouseEventArgs A_0)
bij C1.Win.C1FlexGrid.ab.l(MouseEventArgs A_0)
bij C1.Win.C1FlexGrid.C1FlexGridBase.OnMouseDown(MouseEventArgs e)
bij System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
bij System.Windows.Forms.Control.WndProc(Message& m)
bij C1.Win.C1FlexGrid.Util.BaseControls.ScrollableControl.WndProc(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bij System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bij System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bij System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Application.Run(ApplicationContext context)
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
bij RackJobbing.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:regel 81
bij System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
bij System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bij System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bij System.Threading.ThreadHelper.ThreadStart()
我非常感谢任何帮助解决我的问题的帮助,因为我似乎真的找不到解决方案:(
I'm testing the Compiled Queries for the first time.
My current query is:
Shared compiledLatestDate As Func(Of RackJobbingDataDataContext, ArtikelInfoParameters, List(Of VerdelingPlanning)) = _
CompiledQuery.Compile(Of RackJobbingDataDataContext, ArtikelInfoParameters, List(Of VerdelingPlanning))( _
Function(db As RackJobbingDataDataContext, param As ArtikelInfoParameters) _
(From verdplan As VerdelingPlanning In db.VerdelingPlannings _
Join artPlan As ArtikelPlanning In db.ArtikelPlannings _
On artPlan.VerdelingPlanningID Equals verdplan.VerdelingPlanningID _
Join levDet As LeveringDetail In db.LeveringDetails _
On levDet.ArtikelPlanningID Equals artPlan.ArtikelPlanningID _
Join lev As Levering In db.Leverings _
On lev.LeveringID Equals levDet.LeveringID _
Where artPlan.ArtikelID.Equals(param.artId) _
And lev.WinkelID.Equals(param.winkId) _
And Not levDet.PlanningAantal.Equals(Nothing) _
And levDet.PlanningAantal <> 0 _
And verdplan.Datum < param.datumVerdeling _
Order By verdplan.Datum Descending _
Select levDet))
But i receive an ArgumentNulException was unhandled.
It was advised for LINQ queries to add an object with the required parameters, so this is the class:
Public Class ArtikelInfoParameters
Private _wkId As Guid
Private _artId As Guid
Private _datumVerdeling As DateTime
Public Sub New(ByVal artId As Guid, ByVal winkId As Guid, ByVal datumVerdeling As DateTime)
_artId = artId
_wkId = winkId
_datumVerdeling = datumVerdeling
End Sub
Public Property artId As Guid
Get
Return _artId
End Get
Set(ByVal value As Guid)
_artId = value
End Set
End Property
Public Property winkId As Guid
Get
Return _wkId
End Get
Set(ByVal value As Guid)
_wkId = value
End Set
End Property
Public Property datumVerdeling As DateTime
Get
Return _datumVerdeling
End Get
Set(ByVal value As DateTime)
_datumVerdeling = value
End Set
End Property
End Class
And for the sake of being complete, this is the error i'm receiving.
bij System.Data.Linq.SqlClient.SqlJoin.set_Left(SqlSource value)
bij System.Data.Linq.SqlClient.SqlMultiplexer.Visitor.VisitMultiset(SqlSubSelect sms)
bij System.Data.Linq.SqlClient.SqlVisitor.VisitSubSelect(SqlSubSelect ss)
bij System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
bij System.Data.Linq.SqlClient.SqlVisitor.VisitExpression(SqlExpression exp)
bij System.Data.Linq.SqlClient.SqlMultiplexer.Visitor.VisitSelect(SqlSelect select)
bij System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node)
bij System.Data.Linq.SqlClient.SqlProvider.BuildQuery(ResultShape resultShape, Type resultType, SqlNode node, ReadOnlyCollection`1 parentParameters, SqlNodeAnnotations annotations)
bij System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations)
bij System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Compile(Expression query)
bij System.Data.Linq.CompiledQuery.ExecuteQuery(DataContext context, Object[] args)
bij System.Data.Linq.CompiledQuery.Invoke[TArg0,TArg1,TResult](TArg0 arg0, TArg1 arg1)
bij RackJobbing.UI.ucArtikelInfo.getLatestDate(Guid artikelId) in D:\EasySolutions\TFS\Provoost\Development\RackJobbing\RackJobbing.UI\Snelinvoer\Verdeling\ucArtikelInfo.vb:regel 69
bij RackJobbing.UI.ucArtikelInfo.UpdateInfo() in D:\EasySolutions\TFS\Provoost\Development\RackJobbing\RackJobbing.UI\Snelinvoer\Verdeling\ucArtikelInfo.vb:regel 111
bij RackJobbing.UI.frmPrePlanning.UcVerdeling1_ArtikelWinkelChanged() in D:\EasySolutions\TFS\Provoost\Development\RackJobbing\RackJobbing.UI\Snelinvoer\Verdeling\frmPrePlanning.vb:regel 280
bij RackJobbing.UI.ucVerdeling.grdVerdeling_EnterCell(Object sender, EventArgs e) in D:\EasySolutions\TFS\Provoost\Development\RackJobbing\RackJobbing.UI\Snelinvoer\Verdeling\ucVerdeling.vb:regel 339
bij C1.Win.C1FlexGrid.C1FlexGridBase.OnEnterCell(EventArgs e)
bij C1.Win.C1FlexGrid.C1FlexGridBase.a9()
bij C1.Win.C1FlexGrid.C1FlexGridBase.OnGridChanged(Object sender, GridChangedEventArgs e)
bij C1.Win.C1FlexGrid.C1FlexGrid.OnGridChanged(Object sender, GridChangedEventArgs e)
bij C1.Win.C1FlexGrid.t.bc(GridChangedTypeEnum A_0, Int32 A_1, Int32 A_2, Int32 A_3, Int32 A_4)
bij C1.Win.C1FlexGrid.t.bn(GridChangedTypeEnum A_0)
bij C1.Win.C1FlexGrid.p.n(C1FlexGridBase A_0, CellRange A_1, Boolean A_2)
bij C1.Win.C1FlexGrid.C1FlexGridBase.Select(CellRange rg, Boolean show)
bij C1.Win.C1FlexGrid.ab.o(MouseEventArgs A_0)
bij C1.Win.C1FlexGrid.ab.l(MouseEventArgs A_0)
bij C1.Win.C1FlexGrid.C1FlexGridBase.OnMouseDown(MouseEventArgs e)
bij System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
bij System.Windows.Forms.Control.WndProc(Message& m)
bij C1.Win.C1FlexGrid.Util.BaseControls.ScrollableControl.WndProc(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bij System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bij System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bij System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Application.Run(ApplicationContext context)
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
bij RackJobbing.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:regel 81
bij System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
bij System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bij System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bij System.Threading.ThreadHelper.ThreadStart()
I'd appreciate any help in solving my problem , because i really can't seem to find the solution :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与 SQL 不同,ON 子句的左侧和右侧具有不同的范围可见性。
您需要将 JOIN 之前范围内的变量放在 ON 子句的左侧,并将 JOIN 新范围内的变量放在右侧。
这里我切换了 ON 子句中的变量。
Unlike SQL, the ON clause's left and right sides have different scope visibility.
You need to put variables that were in scope before the JOIN on the left side of the ON clause, and variables that are newly in scope from the JOIN on the right side.
Here I have switched the variables in ON clauses.
解决方案:
解决了我几乎所有的问题,尽管有时当集合中没有值时我会收到 NullReferenceException (它并不总是给出错误,所以我仍在研究这一点)。
Solution:
Solved almost all of my problems, even though i sometimes get a NullReferenceException when there is no value in the collection (it doesn't always give an error, so i'm still looking into that).