Skip to content

Question: How to add computed persisted column with index? #2280

Closed
@IdeaHunter

Description

@IdeaHunter

I want to create a persisted computed column to be able to have index on it in MSSQL.
Im trying following piece of code for mapping but column isn't getting created in sql:

classMap.Property(prop.Name, pMap =>
{
    pMap.Formula("CAST(CASE WHEN [Column1] > [Column2] THEN 1 ELSE 0 END AS bit) PERSISTED");
    pMap.Generated(PropertyGeneration.Always);
    pMap.Update(false);
    pMap.Insert(false);
    pMap.Index($"IX_{type.Name}_{prop.Name}");
});

Can anyone please tell me what im doing wrong?

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