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

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
dresel
Posts: 18
Joined: Tue 20 Nov 2012 13:38

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

Post by 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;");
		}
	}

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

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

Post by 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/postg ... ation.html.

dresel
Posts: 18
Joined: Tue 20 Nov 2012 13:38

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

Post by dresel » Thu 24 Nov 2016 07:47

Well I was trying the http://blog.devart.com/entity-framework ... 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.

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

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

Post by 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
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Fri 09 Dec 2016 19:24

The config.DatabaseScript.Schema.DeleteDatabaseBehaviour option is supported in EF Core: viewtopic.php?f=3&t=34690.

Post Reply