Create database with dotConnect 8.1, EF 6.0.1 and Oracle 11g

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
delarou
Posts: 15
Joined: Thu 07 Apr 2011 15:12

Create database with dotConnect 8.1, EF 6.0.1 and Oracle 11g

Post by delarou » Fri 08 Nov 2013 15:49

Our environment is the following:
- Oracle Database 11g Release 11.2.0.3.0 (64bit)
- Entity Framework 6.0.1
- dotConnect Oracle 8.1.26

I want to create the database from Ef having a simple entity called Country.

Code: Select all

Database.SetInitializer(new DropCreateDatabaseAlways<SomeContext>());
using (var context = new SomeContext())
{
   string sqlscript = (context as IObjectContextAdapter).ObjectContext.CreateDatabaseScript();

   context.Database.Initialize(true);
}
The 'sqlscript' gives the following output. But it seems that it generates syntax for Oracle 12 and not Oracle 11.

Code: Select all

create table [dbo].[COUNTRY] (
    [ID] [int] not null identity,
    [ISOCODE] [nvarchar](8) null,
    [ISEU] [bit] not null,
    [TRANSLATIONDATA] [nvarchar](4000) null,
    primary key ([ID])
);
The 'Initialize' doesn't give an exception but nothing is generated in the database.
I also tried with the connectionstring in direct mode.

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

Re: Create database with dotConnect 8.1, EF 6.0.1 and Oracle 11g

Post by Shalex » Mon 11 Nov 2013 18:23

It seems like your current SQL is generated for System.Data.SqlClient. To employ Devart.Data.Oracle, please replace the existing entityFramework section with the following one:

Code: Select all

   <entityFramework>
      <providers>
         <provider invariantName="Devart.Data.Oracle" type="Devart.Data.Oracle.Entity.OracleEntityProviderServices, Devart.Data.Oracle.Entity, Version=8.1.26.6, Culture=neutral, PublicKeyToken=09af7300eec23701" />
      </providers>
   </entityFramework>
Also change the connection string to the one which uses Devart.Data.Oracle.

delarou
Posts: 15
Joined: Thu 07 Apr 2011 15:12

Re: Create database with dotConnect 8.1, EF 6.0.1 and Oracle 11g

Post by delarou » Tue 12 Nov 2013 22:04

Thx, that was indeed the problem!

Now I get an exception when trying to generate the following model when calling 'CreateDatabaseScript'

Code: Select all

public class SomeContext : DbContext
{
   public DbSet<User> Users { get; set; }

   protected override void OnModelCreating(DbModelBuilder modelBuilder)
   {
      modelBuilder.Entity<SpecialUser>().ToTable("UserSpecial");
   }
}

public abstract class User
{
   public int Id { get; set; }
}

public class SpecialUser : User
{
   public List<Country> Countries { get; set; }
}

public class Country  
{
   public int Id { get; set; }
}
The exception is a 'NullReferenceException'. Note that the same model with SQL Server doesn't generate an error. Also when I comment the line below it works.

Code: Select all

 modelBuilder.Entity<SpecialUser>().ToTable("UserSpecial");
The exception generated by 'CreateDatabaseScript' is

Code: Select all

System.NullReferenceException was unhandled
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=Devart.Data.Oracle.Entity
  StackTrace:
       at Devart.Common.Entity.es.b(ReferentialConstraint A_0)
       at Devart.Common.Entity.es.c(ReferentialConstraint A_0)
       at Devart.Common.Entity.es.a(ReferentialConstraint A_0, EntitySet A_1, EntitySet A_2)
       at Devart.Data.Oracle.Entity.a3.a(ReferentialConstraint A_0, EntitySet A_1, EntitySet A_2)
       at Devart.Common.Entity.es.a(AssociationSet A_0)
       at Devart.Common.Entity.es.t()
       at Devart.Common.Entity.es.u()
       at Devart.Common.Entity.es.am()
       at Devart.Data.Oracle.Entity.OracleEntityProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
       at System.Data.Entity.Internal.DatabaseOperations.Create(ObjectContext objectContext)
       at System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext)
       at System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext)
       at System.Data.Entity.Database.Create(Boolean skipExistsCheck)
       at System.Data.Entity.Database.Create()
       at System.Data.Entity.DropCreateDatabaseAlways`1.InitializeDatabase(TContext context)
       at System.Data.Entity.Internal.InternalContext.<>c__DisplayClasse`1.<CreateInitializationAction>b__d()
       at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
       at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
       at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
       at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
       at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
       at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
       at System.Data.Entity.Internal.InternalContext.Initialize()
       at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes()
       at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()
       at ConsoleApplication1.Program.Main(String[] args) in c:\WorkZone\Repositories\BeCert\src\ConsoleApplication1\Program.cs:line 24
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

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

Re: Create database with dotConnect 8.1, EF 6.0.1 and Oracle 11g

Post by Shalex » Wed 13 Nov 2013 12:57

The bug related to the NRE on the CreateDatabaseScript() method, when the Code-First model is not configured completely, is fixed. We will notify you when the corresponding build of dotConnect for PostgreSQL is available for download.

delarou
Posts: 15
Joined: Thu 07 Apr 2011 15:12

Re: Create database with dotConnect 8.1, EF 6.0.1 and Oracle 11g

Post by delarou » Wed 13 Nov 2013 13:43

Just to be sure, will it also fixed for 'dotConnect for Oracle'?

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

Re: Create database with dotConnect 8.1, EF 6.0.1 and Oracle 11g

Post by Shalex » Wed 13 Nov 2013 16:23

The fix will be included in the next build of dotConnect for Oracle as well.

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

Re: Create database with dotConnect 8.1, EF 6.0.1 and Oracle 11g

Post by Shalex » Thu 14 Nov 2013 18:03

The new (8.1.36) build of dotConnect for Oracle includes the fix. Please try it.

Post Reply