Issue with DataGrid and Filtering on computed property

Hi,

as described in Databases | Radzen Blazor Studio, I have created a computed property to join the columns "FirstName" and "LastName" to one single computed property which I use for a GridColumn.

This works as expected and the Grid shows the computed colmn values.

Now, when I use filtering on that column, I get an exception:

p.FullName.Contains("test"))' could not be translated. Additional information: Translation of member 'FullName' on entity type 'Customer' failed. This commonly occurs when the specified member is unmapped.

First, I thought this was due to the fact that I forgot to add [NotMapped] to the property, but even after I added this attribute, I still get this error. How can use filtering on a computed property?

Thanks for your help!

You cannot translate such property to SQL server since it's not part of the database. You can use ToList() before assigning Data to filter in-memory.

1 Like

You can also check EF's built-in support for computed columns: Generated Values - EF Core | Microsoft Learn

To try that you would need a partial class for the generated DBContext and implement the OnModelBuilding partial method.

public partial class MyContext
{
    partial void OnModelBuilding(ModelBuilder builder)
    {
        modelBuilder.Entity<Person>()
               .Property(p => p.FullName)
               .HasComputedColumnSql("[FirstName] + '  ' + [LastName]");
    }
}
1 Like

Thanks a lot for that hint!