Page 1 of 1

EF Core Codefirst + Computed Column

Posted: Thu 20 Dec 2018 06:27
by Sv01a
oracle dotconnect version - 9.6.646
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();
            });
           }
Migration code:

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);
                });
Migration generated SQL from console output:

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)
      )

Re: EF Core Codefirst + Computed Column

Posted: Sat 22 Dec 2018 18:19
by Shalex
Thank you for your report. We have reproduced the issue and are investigating it. We will notify you about the result.

Re: EF Core Codefirst + Computed Column

Posted: Tue 25 Dec 2018 07:32
by Sv01a
Seems that something like this https://github.com/aspnet/EntityFramewo ... r.cs#L1365 are missed in provider

Re: EF Core Codefirst + Computed Column

Posted: Tue 25 Dec 2018 09:44
by Shalex
Thank you for the additional information.

Re: EF Core Codefirst + Computed Column

Posted: Thu 10 Jan 2019 18:55
by Shalex
The .HasComputedColumnSql functionality in EF Core Code-First Migrations is supported: viewtopic.php?f=1&t=38262.

Re: EF Core Codefirst + Computed Column

Posted: Fri 08 Feb 2019 05:42
by Sv01a
It's works for table creation, but doesn't work for alter/add column.

Alter computed field:

Code: Select all

ALTER TABLE Tests CodeName VARCHAR2(3051 CHAR) DEFAULT NULL
Add new into existing table:

Code: Select all

ALTER TABLE Tests CodeName1 VARCHAR2(3051 CHAR) NULL

Re: EF Core Codefirst + Computed Column

Posted: Thu 14 Feb 2019 10:55
by Shalex
Thank you for your report. We will notify you when the case for alter/add computed column is fixed.

Re: EF Core Codefirst + Computed Column

Posted: Tue 26 Feb 2019 14:05
by Shalex
The .HasComputedColumnSql functionality for the AddColumn and AlterColumn operations in EF Core Code-First Migrations is supported: https://www.devart.com/pub/nuget_oracle_9_6_704.zip. We will notify you when the new public build is available.

Re: EF Core Codefirst + Computed Column

Posted: Fri 29 Mar 2019 12:44
by Shalex
New build of dotConnect for Oracle 9.6.725 is available for download now: viewtopic.php?f=1&t=38518.