EF Core Codefirst + Computed Column
Posted: Thu 20 Dec 2018 06:27
oracle dotconnect version - 9.6.646
ef core version - 2.1.4
Seems that HasComputedColumnSql doesn't work for Oracle:
DBContext:
Migration code:
Migration generated SQL from console output:
ef core version - 2.1.4
Seems that HasComputedColumnSql doesn't work for Oracle:
DBContext:
Code: Select all
public class TestDbContext : DbContext
{
public virtual DbSet<MER> MER { get; set; }
public TestDbContext(DbContextOptions<TestDbContext> options) : base(options)
{
var config = OracleEntityProviderConfig.Instance;
config.CodeFirstOptions.AddTableNameInDefaultIndexName = true;
config.CodeFirstOptions.UseNonUnicodeStrings = true;
config.QueryOptions.CaseInsensitiveComparison = true;
config.QueryOptions.CaseInsensitiveLike = true;
config.Workarounds.DisableQuoting = true;
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<MER>(entity =>
{
entity.Property(e => e.CodeName)
.HasComputedColumnSql($"\"CODE\"||' '||\"NAME\"")
.ValueGeneratedNever();
});
}
Code: Select all
migrationBuilder.CreateTable(
name: "MER",
columns: table => new
{
Id = table.Column<int>(nullable: false),
ParentId = table.Column<int>(nullable: true),
Code = table.Column<string>(maxLength: 50, nullable: true),
Name = table.Column<string>(maxLength: 3000, nullable: true),
CodeName = table.Column<string>(maxLength: 3050, nullable: true, computedColumnSql: "\"CODE\"||' '||\"NAME\""),
OkeiName = table.Column<string>(maxLength: 50, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_MER", x => x.Id);
});
Code: Select all
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (47ms) [Parameters=[], CommandType='Text', CommandTimeout='0']
CREATE TABLE MER (
Id NUMBER(10) GENERATED BY DEFAULT ON NULL AS IDENTITY NOT NULL,
ParentId NUMBER(10) NULL,
Code VARCHAR2(50 CHAR) NULL,
Name VARCHAR2(3000 CHAR) NULL,
CodeName VARCHAR2(3050 CHAR) NULL,
OkeiName VARCHAR2(50 CHAR) NULL,
PRIMARY KEY (Id)
)