Page 1 of 1

Code-First CreateDatabase supported?

Posted: Tue 24 Jun 2014 13:04
by dresel
Hi,

I'm trying to setup Code-First with dotConnect for PostgreSQL. I want the database "lacowiki" to be created if none exist.

When using

Code: Select all

PortalContext context = new PortalContext();
context.Database.Create();
I get an "database "lacowiki" does not exist" exception.

Should this be supported?

When the database exists, seeding or initialization strategies like DropCreateDatabaseAlways / DropCreateDatabaseIfModelChanges are working though...

Re: Code-First CreateDatabase supported?

Posted: Tue 24 Jun 2014 16:38
by Shalex
Please refer to http://www.devart.com/dotconnect/postgr ... ation.html. If this doesn't help, specify your current DeleteDatabaseBehaviour value.

Re: Code-First CreateDatabase supported?

Posted: Wed 25 Jun 2014 14:02
by dresel
I modified the configuration to

Code: Select all

<configSections>
	<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
	<section name="entityFramework"
		type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
		requirePermission="false" />
	<!-- Devart specific configuration section -->
	<section name="Devart.Data.PostgreSql.Entity" type="Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfigurationSection,
		Devart.Data.PostgreSql.Entity" />
</configSections>
<!-- Devart specific configuration (enables creation of database) -->
<Devart.Data.PostgreSql.Entity xmlns="http://devart.com/schemas/Devart.Data.PostgreSql.Entity/1.0">
	<DatabaseScript>
		<Schema DeleteDatabaseBehaviour="Database" />
	</DatabaseScript>
</Devart.Data.PostgreSql.Entity>
Seems to work now as expected, I have one question though. DotConnect creates an empty schema called "Current SCHEMA {GUID}" - whats the purpose of this and can this be avoided?

Re: Code-First CreateDatabase supported?

Posted: Thu 26 Jun 2014 14:48
by Shalex
Please make sure (via dbMonitor) that the "Current SCHEMA {GUID}" schema is created by dotConnect for PostgreSQL. If so, specify the exact (x.x.x) version of your dotConnect for PostgreSQL and send us a small test project so that we can reproduce the issue in our environment.

Re: Code-First CreateDatabase supported?

Posted: Fri 27 Jun 2014 10:29
by dresel
I verified (via dbMonitor) that this statement (CREATE SCHEMA "Current SCHEMA {C353AD3D-7207-416E-A4C4-7FE3BEE0E887}") is executed by dotConnect.

I'm using Devart dotConnect for PostgreSQL Trial 7.3.181.0 (Devart.Data.PostgresSql.Entity shows 7.3.181.6) with EntityFramework 6.1.1 and PostgreSQL 9.3.

I will send you a test project.

Re: Code-First CreateDatabase supported?

Posted: Fri 27 Jun 2014 16:03
by Shalex
Thank you for your test project. We have reproduced the issue and are investigating it.

Re: Code-First CreateDatabase supported?

Posted: Mon 07 Jul 2014 07:43
by dresel
I also found out, that Migrations are not executed when using context.Database.Create, but when you do something like

Code: Select all

context.TestEntities.Create();
which triggers a database creation then Migrations are executed.

Re: Code-First CreateDatabase supported?

Posted: Tue 08 Jul 2014 17:02
by Shalex
dresel wrote:I verified (via dbMonitor) that this statement (CREATE SCHEMA "Current SCHEMA {C353AD3D-7207-416E-A4C4-7FE3BEE0E887}") is executed by dotConnect.
The bug with creating extra schema in the database when config.DatabaseScript.Schema.DeleteDatabaseBehaviour = DeleteDatabaseBehaviour.Database is fixed. We will notify you when the corresponding build of dotConnect for PostgreSQL is available for download.
dresel wrote:I also found out, that Migrations are not executed when using context.Database.Create, but when you do something like

Code: Select all

context.TestEntities.Create();
which triggers a database creation then Migrations are executed.
The test project you have sent us includes the code:

Code: Select all

		private static void Main(string[] args)
		{
			PgSqlMonitor monitor = new PgSqlMonitor() { IsActive = true };
			TestContext context = new TestContext();
			if (context.Database.Exists())
			{
				context.Database.Delete();
			}
			context.Database.Create();
And this code does (re)create a database with the "TestEntity" table. How should we modify your test project to reproduce the issue?

Re: Code-First CreateDatabase supported?

Posted: Thu 10 Jul 2014 07:20
by dresel
Yes. Add

Code: Select all

Console.WriteLine("Migrations executed.");
to InitialCreate.Up().

When you run the code, Up will not be called. When you change

Code: Select all

context.Database.Create();
to

Code: Select all

context.TestEntities.Create();
Migrations will be called.

Re: Code-First CreateDatabase supported?

Posted: Fri 11 Jul 2014 12:44
by Shalex
Shalex wrote:The bug with creating extra schema in the database when config.DatabaseScript.Schema.DeleteDatabaseBehaviour = DeleteDatabaseBehaviour.Database is fixed. We will notify you when the corresponding build of dotConnect for PostgreSQL is available for download.
New build of dotConnect for PostgreSQL 7.3.201 is available for download!
It can be downloaded from http://www.devart.com/dotconnect/postgr ... nload.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=3&t=29946.
dresel wrote:Add

Code: Select all

Console.WriteLine("Migrations executed.");
to InitialCreate.Up().

When you run the code, Up will not be called.
We have reproduced the issue and are investigating it.