I have an account table that has ID auto-increment as true. Now I want to add Computed Column based on which. It can Add new value To the UserCode by the following Logic.
builder.Entity<Account>().Property(p => p.UserCode)
.HasComputedColumnSql(@"CONCAT(CASE WHEN Role= 0 THEN 'ADM'
WHEN Role = 1 then 'ADV'
WHEN Role = 2 then 'INV'
WHEN ROle = 3 then 'EMP' END,
LPAD(ID, 8, '0'))");
Here is the Account Entity and DB set
public DbSet<Account> Accounts { get; set; }
When I am running the migration, It's working fine But when I am executing Update Database, I am getting the following error.
Generated column 'UserCode' cannot refer to the auto-increment column.
PS: I don't want to use any trigger or more than one update statement.