EFCore: DbContext.Database.EnsureCreated() can't create Database

EFCore: DbContext.Database.EnsureCreated() can't create Database

Postby dresel » Fri 18 Nov 2016 09:52

Hi,

I'm using 7.6.763.0 of dcpostgresql76pro.

DbContext.Database.EnsureCreated() throw an "Database 'test' does not exist." exception instead of creating the database.

Code: Select all
   class Program
   {
      static void Main(string[] args)
      {
         var context = new MyDbContext();
         context.Database.EnsureCreated();
      }
   }

   public class MyDbContext : DbContext
   {
      protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
      {
         optionsBuilder.UsePostgreSql(@"Host=localhost;User Id=postgres;Password=postgres;Database=test;Unicode=true;");
      }
   }
dresel
 
Posts: 18
Joined: Tue 20 Nov 2012 13:38

Re: EFCore: DbContext.Database.EnsureCreated() can't create Database

Postby Shalex » Mon 21 Nov 2016 12:16

Please turn on the following option and try again:
Code: Select all
            var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig;
            config.DatabaseScript.Schema.DeleteDatabaseBehaviour = Devart.Data.PostgreSql.Entity.Configuration.DeleteDatabaseBehaviour.Database;

For more information, refer to https://www.devart.com/dotconnect/postgresql/docs/?DBScriptGeneration.html.
Shalex
Devart Team
 
Posts: 7793
Joined: Thu 14 Aug 2008 12:44

Re: EFCore: DbContext.Database.EnsureCreated() can't create Database

Postby dresel » Thu 24 Nov 2016 07:47

Well I was trying the http://blog.devart.com/entity-framework-core-1-entity-framework-7-support.html?_ga=1.75631125.1827866925.1479454278 blog post, there it says:

Additionally, our providers support only a part of provider configuration settings. For example, for config.DatabaseScript.Schema.DeleteDatabaseBehaviour setting, only the DeleteDatabaseBehaviour.ModelObjectsOnly value (default value) is supported.


Did you try your solution? Maybe I did something wrong, but

Code: Select all
      static void Main(string[] args)
      {
         var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig.Instance;
         config.DatabaseScript.Schema.DeleteDatabaseBehaviour = Devart.Data.PostgreSql.Entity.Configuration.DeleteDatabaseBehaviour.Database;

         var context = new MyDbContext();
         context.Database.EnsureDeleted();
         context.Database.EnsureCreated();
      }


still does not work.
dresel
 
Posts: 18
Joined: Tue 20 Nov 2012 13:38

Re: EFCore: DbContext.Database.EnsureCreated() can't create Database

Postby Shalex » Mon 28 Nov 2016 13:31

Your remark is correct, sorry for my mistake.

DeleteDatabaseBehaviour.Database is currently not supported for EF Core. We will notify you when the corresponding feature is implemented.
Shalex
Devart Team
 
Posts: 7793
Joined: Thu 14 Aug 2008 12:44

Re: EFCore: DbContext.Database.EnsureCreated() can't create Database

Postby Shalex » Fri 09 Dec 2016 19:24

The config.DatabaseScript.Schema.DeleteDatabaseBehaviour option is supported in EF Core: http://forums.devart.com/viewtopic.php?f=3&t=34690.
Shalex
Devart Team
 
Posts: 7793
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for PostgreSQL