In EFCore 3.1 I did:
migrationBuilder.CreateTable(
name: "Worker",
columns: t => new {
LastName = t.Column<string>(type: "varchar(64)"),
FirstName = t.Column<string>(type: "varchar(64)"),
MiddleName = t.Column<string>(type: "varchar(64)"),
FullName = t.Column<string>(type: "varchar(128)",
computedColumnSql: @"trim(""LastName"" || ' ' || ""FirstName"" || ' ' || ""MiddleName"")"),
}
)
In EFCore 5.0 this code got error System.NotSupportedException: Generated columns currently must be stored, specify IsStoredComputedColumn in your context's OnModelCreating
I added to DbContext
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Worker>()
.Property(m => m.FullName)
.HasComputedColumnSql(@"trim(""LastName"" || ' ' || ""FirstName"" || ' ' || ""MiddleName"")", stored: true);
}
But got the same error
If I remove computedColumnSql: "..." from migration code, I get general column.
My Entity:
public class Worker
{
public string LastName { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public string FullName { get; set; }
}
Where is the error?
In EFCore 3.1 I did:
In EFCore 5.0 this code got error
System.NotSupportedException: Generated columns currently must be stored, specify IsStoredComputedColumn in your context's OnModelCreatingI added to DbContext
But got the same error
If I remove
computedColumnSql: "..."from migration code, I get general column.My Entity:
Where is the error?