Setting NpgsqlTsVector column using EF Core and reflection

Viewed 60

I have a large number of tables (about 100) and some of them has NpgsqlTsVector column, and those columns are design to preform Full Text Search. Content of those column is build upon jsonb columns in the same table.

Normally procedure should look like (and it works but I want to automate this declaration):

modelBuilder.Entity<VectorInfo>(entity =>
{
    entity
        .HasGeneratedTsVectorColumn 
             (p => p.DocumentVector, "english", p => new { p.ArrivalAirportName, p.DepartureAirportName })
        .HasIndex(p => p.DocumentVector)
        .HasMethod("GIN")
});

So i figured that instead of doing this manually I cold set this up using generics and reflection in entity framework, so I tried:

modelBuilder.Entity<TEntity>(builder =>
{
    builder.HasGeneratedTsVectorColumn(
            entity => (NpgsqlTsVector)entity.GetType().GetProperty(vectorProperty.Name).GetValue(entity),
            "english",
            entity => { selected jsonb type column});
});

And well it does not work, I am getting:

The expression 'entity => Convert(entity.GetType().GetProperty(value(Database.MigrationContext+<>c__DisplayClass8_0`1[Database.Models.Entities.adMarkers]).vectorProperty.Name).GetValue(entity), NpgsqlTsVector)' is not a valid member access expression. The expression should represent a simple property or field access: 't => t.MyProperty'. (Parameter 'memberAccessExpression')

So I am stuck here. And my question is this procedure possible (as I see there is no other overload for HasGeneratedTsVectorColumn). And what am I doing wrong here?

0 Answers
Related