This is a migrated thread and some comments may be shown as answers.
Filter on readonly property
4 Answers 48 Views
This is a migrated thread and some comments may be shown as answers.
2next
Top achievements
Rank 1
2next asked on 01 Oct 2019, 06:06 PM

Hi,

I get this error when I try to filter a string readonly property:

Eccezione generata: 'System.InvalidOperationException' in Microsoft.EntityFrameworkCore.dll
Eccezione generata: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Eccezione generata: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Eccezione generata: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Eccezione generata: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.dll
Eccezione generata: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Eccezione generata: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Eccezione generata: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.dll
Eccezione generata: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Eccezione generata: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Eccezione generata: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Eccezione generata: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'Dc6XDD5v9mxLyyypeL63oqa9jPGzD6bu1FJDHIMCCt4'.

System.InvalidOperationException: The LINQ expression 'Where<Card>(
    source: OrderByDescending<Card, Nullable<DateTime>>(
        source: Where<Card>(
            source: DbSet<Card>, 
            predicate: (c) => (Unhandled parameter: __pngruppo_0).Contains(c.IdAccessPoint) && c.Stato.Value == 1), 
        keySelector: (c) => c.DataInserimento), 
    predicate: (c) => c.Cognome.ToLower().Contains("t"))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.<VisitMethodCall>g__CheckTranslated|8_0(ShapedQueryExpression translated, <>c__DisplayClass8_0& )
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at Telerik.DataSource.Extensions.QueryableExtensions.Count(IQueryable source)
   at Telerik.DataSource.Extensions.QueryableExtensions.CreateDataSourceResult[TModel,TResult](IQueryable queryable, DataSourceRequest request, Func`2 selector)
   at Telerik.DataSource.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable queryable, DataSourceRequest request)
   at Telerik.DataSource.Extensions.QueryableExtensions.<>c__DisplayClass3_0.<ToDataSourceResultAsync>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Bipoint.Data.Model.BipointService.GetCards_Inseriti_PN(DataSourceRequest request) in C:\Users\francesco\Documents\myprojects\2Next\Projects\Bipoint\prove\BipointB\Data\Model\BipointService.cs:line 31
   at Bipoint.Pages.Pn.ReadItems(GridReadEventArgs args) in C:\Users\francesco\Documents\myprojects\2Next\Projects\Bipoint\prove\BipointB\Pages\Pn.razor:line 62
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Telerik.Blazor.Components.TelerikGridBase`1.ProcessData()
   at Telerik.Blazor.Components.TelerikGridBase`1.OnFilterChange(FilterDescriptorBase filter)
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Telerik.Blazor.Components.Grid.GridFilterHeaderBase`1.Filter(FilterDescriptor filterDescriptor)
   at Telerik.Blazor.Components.Grid.GridFilterHeaderBase`1.OnValueChanged(Object newValue)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_0(Object state)
   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteSynchronously(TaskCompletionSource`1 completion, SendOrPostCallback d, Object state)
   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<.cctor>b__23_0(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteBackground(WorkItem item)
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint '/_blazor'
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 17300.942ms 101 
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll

 

this is the grid definition:

 

 <TelerikGrid Data="@Inseriti" Height="100%" Class="fill-height"
                         Pageable="true" Sortable="true" Groupable="true"
                         PageSize=25 TotalCount="@Total"
                         OnRead=@ReadItems
                         FilterMode="Telerik.Blazor.GridFilterMode.FilterRow">
                <GridColumns>
                    <GridColumn Field="@(nameof(Card.Numero))" Title="Barcode" />
                    <GridColumn Field="@(nameof(Card.Cognome))" Title="Cognome" Groupable="false"/>
                </GridColumns>
            </TelerikGrid>

 

the Card is a EF class:

 public partial class Card
    {

      public int IdCard { get; set; }
        public int IdPatient { get; set; }

 

4 Answers, 1 is accepted

Sort by
0
2next
Top achievements
Rank 1
answered on 01 Oct 2019, 06:12 PM

(accidentally posted before to complete)

   public string Cognome { get => this.Patient.Cognome; }

 

than the EF method:
  public async Task<IEnumerable<Card>> GetCards(DataSourceRequest request)
        {
            using (Context Db = new Context())
            {
                var list = from x in Db.Card
                        select x;

                var result = await list.ToDataSourceResultAsync(request);
                return result.Data as IEnumerable<Card>;
            }
        }

 

 

if I filter the Numero property (string) all works fine.

If I try to filter the Cognome property (string too) the eccor occurs.

0
Accepted
2next
Top achievements
Rank 1
answered on 01 Oct 2019, 06:21 PM

UPDATE:

Sorry, It's no Telerik fault.

EF Core linq query fails translating a condition on a partial readonly property of the class.

something like this:

 var list = from x in Db.Card
                        where x.Cognome.Contains("p")
                        select x;
give the error I mentioned before.
Thanks anyway

 

0
2next
Top achievements
Rank 1
answered on 02 Oct 2019, 02:51 PM

UPDATE 2:

After further investigation I read about breaking changes in EF Core 3.0 preview 4 that disallow client-evaluation of query that cannot be propertly translate in SQL. For those interested read here .

Then in case of computed properties (as Telerik Blazor Knowledge Base suggests here Bind to navigation properties in complex objects and as I have done in the code above) it needs to use one of these solution mentioned here

But using Templates I should avoid the client-eval problem, so I change the following code:

 <GridColumn Field="@(nameof(Card.Patient.Cognome))" Title="Nome" Groupable="false">
       <Template>
        @((context as Card).Patient.Cognome)
       </Template>
 </GridColumn>

First of all, If I omit Field="@(nameof(Card.Patient.Cognome))" the app hang with this error:
System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at Telerik.Blazor.Components.Grid.Extensions.ColumnExtensions.GroupTitles(IEnumerable`1 columns)
   at Telerik.Blazor.Components.TelerikGrid`1.<BuildRenderTree>b__0_1(RenderTreeBuilder __builder2)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at Microsoft.AspNetCore.Components.CascadingValue`1.Render(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint '/_blazor'
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 9533.2773ms 101 

Otherwise, If I try to filter the field (with FilterRow option) I get another error:

System.ArgumentNullException: Value cannot be null. (Parameter 'conversionType')
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType)
   at Telerik.Blazor.Components.Grid.GridFilterHeaderBase`1.OnValueChanged(Object newValue)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_0(Object state)
   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteSynchronously(TaskCompletionSource`1 completion, SendOrPostCallback d, Object state)
   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<.cctor>b__23_0(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteBackground(WorkItem item)
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint '/_blazor'
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 5296.0234ms 101 
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll


If I try to filter the field (with FilterMenu option) I get again another different error:
System.ArgumentException: Invalid property or field - 'Nome' for type: Card
   at Telerik.DataSource.Expressions.MemberAccessTokenExtensions.CreateMemberAccessExpression(IMemberAccessToken token, Expression instance)
   at Telerik.DataSource.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName)
   at Telerik.DataSource.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName, Boolean liftMemberAccessToNull)
   at Telerik.DataSource.Expressions.PropertyAccessExpressionBuilder.CreateMemberAccessExpression()
   at Telerik.DataSource.Expressions.FilterDescriptorExpressionBuilder.CreateMemberExpression()
   at Telerik.DataSource.Expressions.FilterDescriptorExpressionBuilder.CreateBodyExpression()
   at Telerik.DataSource.FilterDescriptor.CreateFilterExpression(ParameterExpression parameterExpression)
   at Telerik.DataSource.FilterDescriptorBase.CreateFilterExpression(Expression instance)
   at Telerik.DataSource.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpression()
   at Telerik.DataSource.CompositeFilterDescriptor.CreateFilterExpression(ParameterExpression parameterExpression)
   at Telerik.DataSource.FilterDescriptorBase.CreateFilterExpression(Expression instance)
   at Telerik.DataSource.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpression()
   at Telerik.DataSource.Expressions.FilterExpressionBuilder.CreateFilterExpression()
   at Telerik.DataSource.Extensions.QueryableExtensions.Where(IQueryable source, IEnumerable`1 filterDescriptors)
   at Telerik.DataSource.Extensions.QueryableExtensions.CreateDataSourceResult[TModel,TResult](IQueryable queryable, DataSourceRequest request, Func`2 selector)
   at Telerik.DataSource.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable queryable, DataSourceRequest request)
   at Telerik.DataSource.Extensions.QueryableExtensions.<>c__DisplayClass3_0.<ToDataSourceResultAsync>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Bipoint.Data.Model.BipointService.GetCards_Inseriti_PN(DataSourceRequest request) in C:\Users\francesco\Documents\myprojects\2Next\Projects\Bipoint\prove\BipointB\Data\Model\BipointService.cs:line 31
   at Bipoint.Pages.Pn.ReadItems(GridReadEventArgs args) in C:\Users\francesco\Documents\myprojects\2Next\Projects\Bipoint\prove\BipointB\Pages\Pn.razor:line 62
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Telerik.Blazor.Components.TelerikGridBase`1.ProcessData()
   at Telerik.Blazor.Components.TelerikGridBase`1.OnFilterChange(FilterDescriptorBase filter)
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Telerik.Blazor.Components.Common.Filters.FilterMenu.TelerikFilterMenuBase.Filter()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint '/_blazor'
Eccezione generata: 'System.ObjectDisposedException' in Microsoft.AspNetCore.Components.dll
Eccezione generata: 'System.ObjectDisposedException' in Microsoft.AspNetCore.Components.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Eccezione generata: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 25149.4359ms 101 
Eccezione generata: 'System.InvalidOperationException' in Microsoft.JSInterop.dll

I'm sorry for the long post and a bit confused, but I hope can help you to improve your product.
Thanks

0
Marin Bratanov
Telerik team
answered on 03 Oct 2019, 08:48 AM

Hi,

As the KB article you found states - at the moment only flat data models are supported. Nesting objects causes exceptions.

We had a spike of similar requests recently, so I have reopened the investigation into the ability to support nested (complex, navigation, or whatever else you may call them) models. Here's a link for a page you can Follow: https://feedback.telerik.com/blazor/1432615-support-for-nested-complex-models.

 

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor
Tags
Grid
Asked by
2next
Top achievements
Rank 1
Answers by
2next
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or