efcore.pg icon indicating copy to clipboard operation
efcore.pg copied to clipboard

Dynamic `config` parameter for `HasGeneratedTsVectorColumn`

Open shoooe opened this issue 4 years ago • 1 comments

The current signature of HasGeneratedTsVectorColumn is:

public static EntityTypeBuilder<TEntity> HasGeneratedTsVectorColumn<TEntity>(
    this EntityTypeBuilder<TEntity> entityTypeBuilder, 
    Expression<Func<TEntity, NpgsqlTsVector>> tsVectorPropertyExpression, 
    string config, 
    Expression<Func<TEntity, object>> includeExpression
) where TEntity : class;

and its usage is this:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Product>()
        .HasGeneratedTsVectorColumn(
            p => p.SearchVector,
            "english",  // <--- config parameter
            p => new { p.Name, p.Description })
        .HasIndex(p => p.SearchVector)
        .HasMethod("GIN");
}

The config parameter currently can only be statically defined. Postgres, on the other hand, allows for that parameter to be a column of the table and be therefore dynamic.

Is there a reason for why it wasn't defined as:

public static EntityTypeBuilder<TEntity> HasGeneratedTsVectorColumn<TEntity>(
    this EntityTypeBuilder<TEntity> entityTypeBuilder, 
    Expression<Func<TEntity, NpgsqlTsVector>> tsVectorPropertyExpression, 
    Expression<Func<TEntity, string>> configExpression, 
    Expression<Func<TEntity, object>> includeExpression
) where TEntity : class;

so that it could be used as:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Product>()
        .HasGeneratedTsVectorColumn(
            p => p.SearchVector,
            p => p.Language,  // <--- config parameter
            p => new { p.Name, p.Description })
        .HasIndex(p => p.SearchVector)
        .HasMethod("GIN");
}

?

The use case I'm on at the moment is that of full text search applies to a table which may have rows of different languages. Something similar to what is described in this SO question.

Are PRs welcome for adding that? Is this on some roadmap?

Thanks

shoooe avatar Dec 18 '21 17:12 shoooe

Is there a reason for why it wasn't defined as:

No real reason... This method is nothing more than some thin sugar, you can just as well bypass it entirely and has HasComputedColumnSql directly. If you'd like to submit a PR adding an overload that accepts and expression, by all means.

roji avatar Dec 18 '21 22:12 roji