VirtualQueryableCollectionView with select query

8 posts, 0 answers
  1. Pawel
    Pawel avatar
    39 posts
    Member since:
    Apr 2014

    Posted 07 Oct 2014 Link to this post

    I have case in my code where I use VirtualQueryableCollectionView bind to RadGridView. I want to after VirtualQueryableCollectionView load records from query map to other objects. Something like that:

    using (var workRepo = new WorkRepository())
    {
        IQueryable<WorkViewModel> works = workRepo.All<Work>().OrderBy("Title").Select(work => new WorkViewModel(work));
        virtualCollection = new VirtualQueryableCollectionView(works) { LoadSize = 50 };
    }

    This will allow me to bind to WorkViewModel which contains extra logic. But constructor throws exception:

    System.NotSupportedException was caught
      HResult=-2146233067
      Message=Only parameterless constructors and initializers are supported in LINQ to Entities.
      Source=EntityFramework
      StackTrace:
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.NewTranslator.TypedTranslate(ExpressionConverter parent, NewExpression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateSet(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.AggregateTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()
           w System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
           w System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()
           w System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
           w System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
           w System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
           w System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
           w System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
           w System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
           w System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
           w System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
           w System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable`1 sequence)
           w System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
           w System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression)
           w System.Data.Entity.Internal.Linq.DbQueryProvider.Execute(Expression expression)
           w Telerik.Windows.Data.QueryableExtensions.Count(IQueryable source)
           w Telerik.Windows.Data.VirtualQueryableCollectionView..ctor(IEnumerable source, Type itemType)
           w Telerik.Windows.Data.VirtualQueryableCollectionView..ctor(IEnumerable source)
           w Xplus.RNX.WpfClient.UI.ViewModels.MainViewModel.FillCollections() w d:\Users\ppiechnik\Documents\Visual Studio 2012\Projects\RNX\Xplus.RNX\Xplus.RNX.WpfClient\UI\ViewModels\MainViewModel.cs:wiersz 743
      InnerException:

    Are there any possibilities to force VirtualQueryableCollectionView to map loaded objects to other objects.
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 09 Oct 2014 Link to this post

    Hello Pawel,

    Generally, the exception you get is not related to the VirtualQueryableCollectionView. My recommendation would be to take a look at some of the following threads for a reference:
    1. Only parameterless constructors and initializers are supported in LINQ to Entities
    2. Only parameterless constructors and initializers are supported in LINQ to Entities message
    3. LINQ to Entites 'parameterless constructor' error
    4. Why "Only Parameterless Constructors And Initializers Are Supporte
    5. Only parameterless constructors and initializers are supported in LINQ to Entities

    I hope that helps, but if you have any other problems related to Telerik controls, let us know.


    Regards,
    Maya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Pawel
    Pawel avatar
    39 posts
    Member since:
    Apr 2014

    Posted 09 Oct 2014 in reply to Maya Link to this post

    My bad. I could search correction by error message but I'm afraid that I came across another exception. I changed my code:

    using (var workRepo = new WorkRepository())
    {
        IQueryable<WorkViewModel> works = workRepo.All<Work>().OrderBy("Title").Select(work => new WorkViewModel { Work = work });
        WorksHierarchy = new VirtualQueryableCollectionView(works) { LoadSize = 50 };
    }

    and when RadGridView triggers VirtualQueryableCollectionView to load records VirtualQueryableCollectionView throws exception after ItemsLoading event (ItemsLoading occurs but ItemsLoaded not):

    System.NotSupportedException was unhandled
      HResult=-2146233067
      Message=Unable to create a null constant value of type 'System.Object'. Only entity types, enumeration types or primitive types are supported in this context.
      Source=EntityFramework
      StackTrace:
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter parent, ConstantExpression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateSet(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.ThenByTranslatorBase.Translate(ExpressionConverter parent, MethodCallExpression call)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateSet(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateSet(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
           w System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()
           w System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
           w System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()
           w System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
           w System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
           w System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
           w System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
           w System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
           w System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
           w Telerik.Windows.Data.VirtualQueryableCollectionView.LoadItems(Int32 startIndex, IEnumerable items)
           w Telerik.Windows.Data.VirtualQueryableCollectionView.<>c__DisplayClass6.<Load>b__5()
           w System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           w MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           w System.Windows.Threading.DispatcherOperation.InvokeImpl()
           w System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
           w System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           w System.Windows.Threading.DispatcherOperation.Invoke()
           w System.Windows.Threading.Dispatcher.ProcessQueue()
           w System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           w MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           w MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
           w System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           w MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           w System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
           w MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           w MS.Win32.UnsafeNativeMethods.MessageBox(HandleRef hWnd, String text, String caption, Int32 type)
           w System.Windows.MessageBox.ShowCore(IntPtr owner, String messageBoxText, String caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult, MessageBoxOptions options)
           w System.Windows.MessageBox.Show(String messageBoxText)
           w Xplus.RNX.WpfClient.App.Main() w d:\Users\ppiechnik\Documents\Visual Studio 2012\Projects\RNX\Xplus.RNX\Xplus.RNX.WpfClient\App.xaml.cs:wiersz 115
           w System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           w System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           w Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           w System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           w System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           w System.Threading.ThreadHelper.ThreadStart()
      InnerException:

    I searched that this exception appears because linq-to-entities doesn't support extra classes, only primitive types, so in my case probably WorkViewModel will be extra class. I suppose that VirtualQueryableCollectionView tries to do some operations with WorkViewModel objects and then it throws exception. there any solution to that?

    I wonder if there is any other solution, setting aside an error, which allows to work with VirtualQueryableCollectionView allowing me to map one objects to another.
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 14 Oct 2014 Link to this post

    Hello Pawel,

    The exception you get does not seem to be related to VirtualQueryableCollectionView or to a Telerik control. I guess you will get the same exception if you work with other IQueryable as well. 
    Nevertheless, I prepared a small project mapping an object to another one and passing it to the collection. I hope that helps. 


    Regards,
    Maya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Pawel
    Pawel avatar
    39 posts
    Member since:
    Apr 2014

    Posted 14 Oct 2014 in reply to Maya Link to this post

    This code:
    var clubs = Club.GetClubs().AsEnumerable();
     
    IQueryable<ClubViewModel> clubViewModels = clubs
            .OrderBy(c => c.Name)
            .Select(c => new ClubViewModel() { CityClub = c, Name = c.Name + "ViewModel" })
            .AsQueryable<ClubViewModel>();
     
    var source = new VirtualQueryableCollectionView(clubViewModels) { LoadSize = 50 };
     
    this.clubsGrid.ItemsSource = source;

    indicates that I need to load all items before I arrange mapping. Am I right?
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 15 Oct 2014 Link to this post

    Hi Pawel,

    The exception you get points that you cannot create a null value constant that refers to the item you are trying to wrap. So, you need to have if different than null in order your LINQ expression to run smoothly. 


    Regards,
    Maya
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  8. Pawel
    Pawel avatar
    39 posts
    Member since:
    Apr 2014

    Posted 11 May 2015 in reply to Maya Link to this post

    Could give some sample code how it should be done?
  9. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 14 May 2015 Link to this post

    Hello,

    I am afraid we do not have such an exact demo to suggest. You can find more information on the collection in the Using Data Virtualization documentation.

    Regards,
    Dimitrina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready