SelectNextSegment()

Hi,

I call DataContext.ExecuteQuery<T>("SELECT TOP 20 * FROM CertainTable") in the enclosed code. Depending on the table queried, an exception is raised. It appears that when the ExecResults<T> are enumerated in a foreach loop the first object returned is null. In Northwind, Orders, Territories, and EmployeeTerritories always raise an exception. All other tables in Northwind do not raise exceptions. AdventureWorks exhibits the same behavior. Consistently, only certain tables will raise exceptions.

Perhaps it was something with my generated DataContext, but queries to the Orders table, Territories table and EmployeeTerritories table using the same DataContext in a separate console program do not raise exceptions.

Any thoughts

Kind Regards,

Rana Ian

---

IEnumerable SelectSegment()

{

IEnumerable newSegment = null;

MethodInfo miGenericDefinition = m_CurrentTableData.Table.Context.GetType().GetMethod("ExecuteQuery");

Type[] aMethodTypeParameters = { m_CurrentTableData.Table.RowType };

MethodInfo miExecuteQuery = miGenericDefinition.MakeGenericMethod(aMethodTypeParameters);

StringBuilder sbQuery;

if (m_nCurrentSegmentIndex == 1)

{

sbQuery = this.BuildSelectQuery(new Nullable<int>(c_nSegmentLength));

}

else

{

// m_nCurrentSegmentIndex starts at 1

int nCurrentSegmentedRowCount = c_nSegmentLength * (m_nCurrentSegmentIndex - 1);

int nNextSegmentedRowCount = nCurrentSegmentedRowCount + c_nSegmentLength;

// Build Query

sbQuery = this.BuildSelectQuery(new Nullable<int>(nNextSegmentedRowCount));

sbQuery.Append("EXCEPT ");

StringBuilder sbExceptQuery = this.BuildSelectQuery(new Nullable<int>(nCurrentSegmentedRowCount));

sbQuery.Append(sbExceptQuery.ToString());

}

object[] aMethodInvokeParameters = { sbQuery.ToString(), new object[] { } };

newSegment = (IEnumerable)miExecuteQuery.Invoke(

m_CurrentTableData.Table.Context,

aMethodInvokeParameters);

return newSegment;

}

---

System.ArgumentException was unhandled
Message="Argument types do not match"
Source="System.Query"
StackTrace:
at System.Expressions.Expression.ValidateSameArgTypes(Type left, Type right) in c:\PdcBuild\query\System.Query\expression.cs:line 507
at System.Expressions.Expression.EQ(Expression left, Expression right) in c:\PdcBuild\query\System.Query\expression.cs:line 215
at System.Data.DLinq.Model.SimpleTranslator.BuildEQ(Expression left, Expression right) in c:\PdcBuild\query\DLinq\Model\Translator.cs:line 213
at System.Data.DLinq.Model.SimpleTranslator.GetLink(LinkExpression link) in c:\PdcBuild\query\DLinq\Model\Translator.cs:line 174
at System.Data.DLinq.SqlClient.DeferredSourceReader`1.Read(ReadSession session, RowReader reader) in c:\PdcBuild\query\DLinq\Engine\Reader.cs:line 393
at System.Data.DLinq.SqlClient.DeferredSourceReadWriter`2.ReadWrite(ReadSession session, RowReader reader, T obj) in c:\PdcBuild\query\DLinq\Engine\Reader.cs:line 354
at System.Data.DLinq.SqlClient.ObjectReader`1.Read(ReadSession session, RowReader reader) in c:\PdcBuild\query\DLinq\Engine\Reader.cs:line 166
at System.Data.DLinq.SqlClient.SqlQueryEnumerator`1.get_Current() in c:\PdcBuild\query\DLinq\Engine\SqlQuerySession.cs:line 166
at System.Data.DLinq.SqlClient.SqlQueryEnumerator`1.System.Collections.IEnumerator.get_Current() in c:\PdcBuild\query\DLinq\Engine\SqlQuerySession.cs:line 157
at Trtiya.Controls.DLinq.DataContextEditor.SelectNextSegment() in c:\Projects\DLinqDataContextEditorExample\Trtiya.Controls\DLinq\DataContextEditor.xaml.cs:line 291
at Trtiya.Controls.DLinq.DataContextEditor.SelectCleanFirstSegment() in c:\Projects\DLinqDataContextEditorExample\Trtiya.Controls\DLinq\DataContextEditor.xaml.cs:line 265
at Trtiya.Controls.DLinq.DataContextEditor.m_lbDataContext_SelectionChanged(Object sender, SelectionChangedEventArgs e) in c:\Projects\DLinqDataContextEditorExample\Trtiya.Controls\DLinq\DataContextEditor.xaml.cs:line 1031
at System.Windows.Controls.SelectionChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.ListBox.OnSelectionChanged(SelectionChangedEventArgs e)
at System.Windows.Controls.Primitives.Selector.SelectionChanger.End()
at System.Windows.Controls.Primitives.Selector.SetSelectedHelper(Object item, FrameworkElement UI, Boolean selected)
at System.Windows.Controls.Primitives.Selector.NotifyIsSelectedChanged(FrameworkElement container, Boolean selected, RoutedEventArgs e)
at System.Windows.Controls.Primitives.Selector.OnSelected(Object sender, RoutedEventArgs e)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.ListBoxItem.OnSelected(RoutedEventArgs e)
at System.Windows.Controls.ListBoxItem.OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty dp, PropertyMetadata metadata, Boolean isCoerceValue, Boolean isOldValueValid, Object oldValue, ValueSource oldValueSource, Boolean oldValueIsModified, Boolean oldValueIsDeferred, Boolean coerceWithDeferredReference, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at System.Windows.Controls.ListBox.NotifyListItemClicked(ListBoxItem item)
at System.Windows.Controls.ListBoxItem.OnMouseLeftButtonDown(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonDownThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at DLinqDataContextEditorExample.MyApp.Main() in c:\Projects\DLinqDataContextEditorExample\DLinqDataContextEditorExample\obj\Debug\MyApp.g.cs:line 50
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()



Answer this question

SelectNextSegment()

  • Doppalapudi

    Matt,

    I really appreciate the response. You saved me a lot of debugging.

    Cheers,

    Rana


  • dev_shiv

    That's for pointing this out. This is a known problem that will be fixed in the next preview.

  • Hasnul

    This is the exact location where the exception is raised.

    void SelectNextSegment()

    {

    if (m_nCurrentSegmentIndex != m_nSegmentTotal)

    {

    m_nCurrentSegmentIndex++;

    m_tbCurrentSegmentIndex.Text = m_nCurrentSegmentIndex.ToString();

    int nNextToLast = m_nSegmentTotal - 1;

    if (m_nCurrentSegmentIndex == nNextToLast ||

    m_nCurrentSegmentIndex == m_nSegmentTotal)

    {

    // Check if row count has grown

    this.CalculateSegmentTotal();

    }

    IEnumerable newSegment = this.SelectSegment();

    // Required workaround until next DLinq release

    // workaround collection allows entites to be commited to db

    m_WorkaroundEntityCollection.Clear();

    // Exception thrown at next line

    foreach (object obj in newSegment)

    {

    m_WorkaroundEntityCollection.Add(obj);

    }

    // Show new segment

    m_lvRows.ItemsSource = m_WorkaroundEntityCollection;

    }

    }


  • SelectNextSegment()