0

I am using .NET Core 3.1, Microsoft.EntityFrameworkCore 3.1.9 and Npgsql 4.1.9. ProductRelease database entity has a version column - a string of numbers separated by a dot in major.minor.build.revision format. I would like to retrieve all the records where version <= 12.5.3.102197.

[Table("product_release", Schema = "test")]
public partial class ProductRelease
{
    [Key]
    [Column("id")]
    public int Id { get; set; }
    
    [Column("version")]
    [StringLength(32)]
    public string Version { get; set; }
}

I found a question where it is explained how to do it in raw SQL with string_to_array built-in function like this:

SELECT
    *
FROM
    test.product_release pr
WHERE
    string_to_array(pr.version, '.')::int[] <= string_to_array('12.5.3.102197', '.')::int[];

How can I translate this query to EF Core (Npgsql). Is there a way to call string_to_array function from EF Core? I would like to avoid writing raw SQL queries.

3
  • Better introduce new SQL Function and map it in EF Core. Commented Feb 1, 2023 at 12:06
  • There's current no translation to string_to_array - you can open an issue on github.com/npgsql/efcore.pg to request that this be added. Commented Feb 1, 2023 at 21:56
  • I submitted a feature request: github.com/npgsql/efcore.pg/issues/2636 Commented Feb 2, 2023 at 6:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.