EF Core Codefirst + Computed Column

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
Sv01a
Posts: 5
Joined: Mon 12 Jan 2015 13:01

EF Core Codefirst + Computed Column

Post by Sv01a » 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:

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

Shalex
Site Admin
Posts: 8747
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Codefirst + Computed Column

Post by Shalex » Sat 22 Dec 2018 18:19

Thank you for your report. We have reproduced the issue and are investigating it. We will notify you about the result.

Sv01a
Posts: 5
Joined: Mon 12 Jan 2015 13:01

Re: EF Core Codefirst + Computed Column

Post by Sv01a » Tue 25 Dec 2018 07:32

Seems that something like this https://github.com/aspnet/EntityFramewo ... r.cs#L1365 are missed in provider

Shalex
Site Admin
Posts: 8747
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Codefirst + Computed Column

Post by Shalex » Tue 25 Dec 2018 09:44

Thank you for the additional information.

Shalex
Site Admin
Posts: 8747
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Codefirst + Computed Column

Post by Shalex » Thu 10 Jan 2019 18:55

The .HasComputedColumnSql functionality in EF Core Code-First Migrations is supported: viewtopic.php?f=1&t=38262.

Sv01a
Posts: 5
Joined: Mon 12 Jan 2015 13:01

Re: EF Core Codefirst + Computed Column

Post by Sv01a » Fri 08 Feb 2019 05:42

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

Shalex
Site Admin
Posts: 8747
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Codefirst + Computed Column

Post by Shalex » Thu 14 Feb 2019 10:55

Thank you for your report. We will notify you when the case for alter/add computed column is fixed.

Shalex
Site Admin
Posts: 8747
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Codefirst + Computed Column

Post by Shalex » Tue 26 Feb 2019 14:05

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.

Shalex
Site Admin
Posts: 8747
Joined: Thu 14 Aug 2008 12:44

Re: EF Core Codefirst + Computed Column

Post by Shalex » Fri 29 Mar 2019 12:44

New build of dotConnect for Oracle 9.6.725 is available for download now: viewtopic.php?f=1&t=38518.

Post Reply