Skip to content

Support define computed column SQL using LINQ expression #36832

@CoreDX9

Description

@CoreDX9

What problem are you trying to solve?

Now EF Core has method HasComputedColumnSql to define computed column. But it's a raw text. If using HasColumnName to modify column name, computed column sql will not reflect changes. Especially when these methods are called in different places, it is difficult to detect the problem. Or when sql expressions of the same .NET type differ in multiple sql dialects, HasComputedColumnSql are incompatible between different databases. For example, DateTimeOffset(datetimeoffset(7) in SqlServer, datetime(6) in MySql) and bool(bit in SqlServer, tinyint(1) in MySql).

Can EF Core provide a method to define computed column SQL using LINQ expression like entity.Property(e => e.SomeProp).HasComputedColumnExpression(e => e.SomeProp1 > e.SomeProp2). Computed column sql will automatically use the correct column name and can be compatible with different databases. Raw sql text will be generated by migration tools and only appears during migration.

Describe the solution you'd like

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions