Page 1 of 1
Invalid Sql for creating TPH tables
Posted: Thu 26 Jun 2014 15:47
by hoekki
When using TPH in Entity Framework, dotConnect generates the following SQL to create the tables:
Code: Select all
CREATE TABLE "Types" (
ID NUMBER(10) NOT NULL,
"Name" NVARCHAR2(50) NOT NULL,
"Discriminator" NVARCHAR2(128) DEFAULT (Undefined) NOT NULL,
CONSTRAINT "PK_Types" PRIMARY KEY (ID)
)
The '(Undefined)' seems quite off. The application throws an "ORA-00984: column not allowed here" exception. I was able to reproduce this problem with other projects. I am using EF 6.1.1, dotConnect 8.4.171.
See:
http://stackoverflow.com/questions/2442 ... art-oracle
Re: Invalid Sql for creating TPH tables
Posted: Wed 02 Jul 2014 08:27
by Shalex
Thank you for your report. We will notify you when the bug is fixed.
Here is a full code for reproducing.
App.config:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
<add name="MyDbContext" connectionString="server=orcl1120;uid=scott;pwd=tiger;" providerName="Devart.Data.Oracle" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<providers>
<provider invariantName="Devart.Data.Oracle" type="Devart.Data.Oracle.Entity.OracleEntityProviderServices, Devart.Data.Oracle.Entity, Version=8.4.191.6, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</providers>
</entityFramework>
</configuration>
C# code:
Code: Select all
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication43
{
class Program
{
static void Main(string[] args)
{
new Devart.Data.Oracle.OracleMonitor() { IsActive = true };
Database.SetInitializer<MyDbContext>(null);
string ddl = (new MyDbContext() as IObjectContextAdapter).ObjectContext.CreateDatabaseScript();
//new MyDbContext().Database.Initialize(false);
}
}
public abstract partial class AbstractType
{
public int Id { get; set; }
public string Name { get; set; }
}
public class NonAbstractType1 : AbstractType {
}
public class NonAbstractType2 : AbstractType
{
}
public class AbstractTypeMap : EntityTypeConfiguration<AbstractType>
{
public AbstractTypeMap()
{
HasKey(t => t.Id);
ToTable("Types");
this.Property(t => t.Name).HasMaxLength(50);
this.Property(t => t.Id).HasColumnName("ID");
this.Property(t => t.Name).HasColumnName("Name");
}
}
public class MyDbContext: DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new AbstractTypeMap());
modelBuilder.Entity<NonAbstractType1>()
.Map(tph =>
{
tph.Requires("Discriminator");
tph.ToTable("Types");
});
}
DbSet<AbstractType> AbstractTypes { get; set; }
}
}
A temporary workaround:
use
Code: Select all
tph.Requires("Discriminator").HasValue("some_value");
instead of
Re: Invalid Sql for creating TPH tables
Posted: Thu 31 Jul 2014 16:13
by Shalex
New build of dotConnect for Oracle 8.4.215 is available for download now!
It can be downloaded from
http://www.devart.com/dotconnect/oracle/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
The bug with generating DDL for creating TPH tables, when the value of discriminator is not set, in the Code-First/Code-First Migrations functionality is fixed in this version.
For more information, please refer to
http://forums.devart.com/viewtopic.php?f=1&t=30078.