Hello,
I am getting the following error when I use the search box in a grid in a Blazor application using 18.3.0.48 controls when the grid has a boolean field.
System.InvalidOperationException
HResult=0x80131509
Message=The LINQ expression 'DbSet<Batches>()
.Where(b => b.BatchID.ToString().ToLower().Contains("a") | b.IsMade.ToString().ToLower().Contains("a"))' could not be translated. Additional information: Translation of method 'bool.ToString' failed. If this method can be mapped to your custom function, see https://go.microsoft.com/fwlink/?linkid=2132413 for more information. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Source=Microsoft.EntityFrameworkCore
The error is thrown from this line in the CustomAdaptor:
int count = DataSource.Cast<Batches>().Count();
The grid contains just an integer ID and boolean "IsMade" field.
@page "/test"
<SfGrid TValue="Batches" ID="Grid" AllowSorting="true" AllowFiltering="true" AllowPaging="true" Toolbar="@(new List<string>() { "Search", "Update", "Cancel" })">
<SfDataManager Adaptor="Adaptors.CustomAdaptor">
<CustomAdaptorBatches></CustomAdaptorBatches>
</SfDataManager>
<GridPageSettings PageSize="20"></GridPageSettings>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Batches.BatchID) HeaderText="ID" Width="50" AllowEditing="false"></GridColumn>
<GridColumn Field=@nameof(Batches.IsMade) Width="30" HeaderText="Made" DisplayAsCheckBox="true" EditType="EditType.BooleanEdit"></GridColumn>
</GridColumns>
</SfGrid>
@code {}
The startup.cs already contains this as other threads have indicated a possible fix
services.AddControllers().AddNewtonsoftJson(options =>
{
// Use the default property (Pascal) casing
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
Thanks!
Corey