Home Forums WPF controls Xceed DataGrid for WPF CompiledQuery LINQ

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24525 |

    Hi all,

    my problem is, that i cannot bind the DataGrid to a CompiledQuery of Linq.
    Here is my Code:

    icontext = new isoft.isoftDataContext();
    IEnumerable<isoft.tbl_kontakt> q = icontext.GetTable<isoft.tbl_kontakt>();
    this.dataGridControl1.ItemsSource= q;

    The above code works, but the following not:

    IEnumerable<isoft.tbl_kontakt> q = GetKontakts(); this.dataGridControl1.ItemsSource= q;

    public IEnumerable<isoft.tbl_kontakt> GetKontakts()
    {
    isoft.isoftDataContext db = new isoft.isoftDataContext();
    return Queries.Getkontakts(db);
    }

    static class Queries
    {
    public static Func<isoft.isoftDataContext, IQueryable<isoft.tbl_kontakt>>
    Getkontakts = System.Data.Linq.CompiledQuery.Compile((isoft.isoftDataContext db) =>
    from c in db.tbl_kontakts select c);

    }

    I get the following error:

    System.InvalidOperationException was unhandled
    Message=”The query results cannot be enumerated more than once.”
    Source=”System.Data.Linq”
    StackTrace:
    bei System.Data.Linq.SqlClient.SqlProvider.OneTimeEnumerable`1.GetEnumerator()
    bei System.Linq.EnumerableQuery`1.GetEnumerator()
    bei System.Linq.EnumerableQuery`1.System.Collections.IEnumerable.GetEnumerator()
    bei System.Windows.Forms.ListBindingHelper.GetFirstItemByEnumerable(IEnumerable enumerable)
    bei System.Windows.Forms.ListBindingHelper.GetListItemTypeByEnumerable(IEnumerable iEnumerable)
    bei System.Windows.Forms.ListBindingHelper.GetListItemType(Object list)
    bei Xceed.Wpf.DataGrid.ItemsSourceHelper.GetFields(IEnumerable itemsSource)
    bei Xceed.Wpf.DataGrid.ItemsSourceHelper.GenerateColumnsFromItemsSource(ColumnCollection columns, IDictionary`2 defaultCellEditors, IEnumerable itemsSource)
    bei Xceed.Wpf.DataGrid.DataGridControl.GenerateColumnsFromItemsSource(IEnumerable itemsSource)
    bei Xceed.Wpf.DataGrid.DataGridControl.OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
    bei System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    bei System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    bei System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    bei System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
    bei System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
    bei System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
    bei System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
    bei System.Windows.Controls.ItemsControl.set_ItemsSource(IEnumerable value)
    bei WPFApplication2.Window1.button2_Click(Object sender, RoutedEventArgs e) in D:\users\rh\Dokumente\Visual Studio Codename Orcas\Projects\Test\WPFApplication2\Window1.xaml.cs:Zeile 128.
    bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
    bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
    bei System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs args)
    bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
    bei System.Windows.Controls.Button.OnClick()
    bei System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
    bei System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
    bei System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
    bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
    bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
    bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
    bei System.Windows.UIElement.ReRaiseEventAs(RoutedEventArgs args, RoutedEvent newEvent)
    bei System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
    bei System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
    bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
    bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
    bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
    bei System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs args)
    bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
    bei System.Windows.Input.InputManager.ProcessStagingArea()
    bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
    bei System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
    bei System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
    bei System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
    bei System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
    bei MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
    bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
    bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
    bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
    bei System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
    bei System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
    bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    bei MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

    Imported from legacy forums. Posted by Gisela (had 945 views)

    Xceed Support
    Member
    Post count: 5658

    Hi,

    As indicated by the stack trace of your error, the IEnumerable<T> returned by the System.Data.Linq.CompiledQuery.Compile() can only be enumerated once.

    If you <i>need</i> to use System.Data.Linq.CompiledQuery.Compile(), then maybe you could make a copy of the returned enumerator’s content and then return the copy.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 327 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    it works now.

    Thank you!

    Imported from legacy forums. Posted by Gisela (had 3792 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.