1

我是第一次测试编译查询。

我目前的查询是:

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

对于解决我的问题的任何帮助,我将不胜感激,因为我似乎真的找不到解决方案:(

4

2 回答 2

0

与 SQL 不同,ON 子句的左侧和右侧具有不同的范围可见性。

您需要将位于 ON 子句左侧的 JOIN 之前范围内的变量放入范围内的变量,以及右侧 JOIN 新范围内的变量。

在这里,我已经切换了 ON 子句中的变量。

From verdplan As VerdelingPlanning In db.VerdelingPlannings _
  Join artPlan As ArtikelPlanning In db.ArtikelPlannings _
  On verdplan.VerdelingPlanningID Equals artPlan.VerdelingPlanningID _
  Join levDet As LeveringDetail In db.LeveringDetails _
  On artPlan.ArtikelPlanningID Equals levDet.ArtikelPlanningID _
  Join lev As Levering In db.Leverings _
  On levDet.LeveringID Equals lev.LeveringID _
于 2011-02-07T16:09:06.647 回答
0

解决方案:

Public Shared CompiledLatestDate As Func(Of RackJobbingDataDataContext, ArtikelInfoParameters, IQueryable(Of VerdelingPlanning)) = _
   CompiledQuery.Compile(Function(db As RackJobbingDataDataContext, artInfo As ArtikelInfoParameters) _
        From verdplan As VerdelingPlanning In db.VerdelingPlannings _
              Join artPlan As ArtikelPlanning In db.ArtikelPlannings _
              On verdplan.VerdelingPlanningID Equals artPlan.VerdelingPlanningID _
              Join levDet As LeveringDetail In db.LeveringDetails _
              On artPlan.ArtikelPlanningID Equals levDet.ArtikelPlanningID _
              Join lev As Levering In db.Leverings _
              On levDet.LeveringID Equals lev.LeveringID _
              Where artPlan.ArtikelID.Equals(artInfo.artId) _
              And lev.WinkelID.Equals(artInfo.winkId) _
              And Not levDet.PlanningAantal.Equals(Nothing) _
              And levDet.PlanningAantal <> 0 _
              And verdplan.Datum < artInfo.datumVerdeling _
              Order By verdplan.Datum Descending _
            Select verdplan)

几乎解决了我的所有问题,即使我有时会在集合中没有值时得到 NullReferenceException(它并不总是给出错误,所以我仍在调查)。

于 2011-02-08T08:04:39.557 回答