EF6 Code First and Postgres

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
snmigerl
Posts: 2
Joined: Sat 28 Dec 2013 23:41

EF6 Code First and Postgres

Post by snmigerl » Thu 01 Jan 2015 17:19

I got a Project that works just fine as long as I define the Connection in the app.config.

But when I try to specify the connection in the Code i get an error, no matter what I try...
System.Data.Entity.Core.MetadataException

Zusätzliche Informationen: Schema specified is not valid. Errors:

Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl

Schema specified is not valid. Errors:
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(3,7) : error 0019: The EntityContainer name must be unique. An EntityContainer with the name 'Schema' is already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(541,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.Table' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(551,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.TableColumn' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(577,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.View' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(589,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ViewColumn' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(615,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.Function' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(640,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.Procedure' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(650,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.Parameter' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(674,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.Constraint' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(686,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.CheckConstraint' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(694,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ConstraintColumn' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(703,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ForeignKeyConstraint' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(712,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ForeignKey' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(723,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ViewConstraint' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(738,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.TableTableConstraint' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(751,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ConstraintConstraintColumn' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(764,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ConstraintForeignKey' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(777,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.FromForeignKeyColumn' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(790,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ToForeignKeyColumn' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(803,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.TableTableColumn' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(816,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ViewViewColumn' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(829,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.FunctionFunctionParameter' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(842,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ProcedureProcedureParameter' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(855,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ViewViewConstraint' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(868,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ViewConstraintConstraintColumn' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(881,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ViewConstraintForeignKey' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(894,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.FromForeignKeyViewColumn' was already defined.
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl(907,8) : error 0019: Each type name in a schema must be unique. Type name 'dotConnect for PostgreSQL.ToForeignKeyViewColumn' was already defined.
Could you give me an Example or a small Sample Project which uses the CodeFirst-Approach and defines the Databse-Connection not in the app.config but in the Code during RunTime.

Thanks

Michael

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

Re: EF6 Code First and Postgres

Post by Shalex » Fri 02 Jan 2015 14:49

You are using *.edml with the DbContext template, aren't you?
JIC:
dotConnect for PostgreSQL includes Entity Developer (*.edml, the Devart Entity Model item) which is our ORM tool for creating/editing models, it has a lot of improvements comparing to EDM Wizard (*.edmx, the ADO.NET Entity Data Model item): http://www.devart.com/entitydeveloper/ed-vs-edm.html.
You can also convert *.edmx to *.edml with Entity Developer: http://forums.devart.com/viewtopic.php?f=32&t=24766.
About DbContext template: http://blog.devart.com/entity-developer ... plate.html.
snmigerl wrote:Could you give me an Example or a small Sample Project which uses the CodeFirst-Approach and defines the Databse-Connection not in the app.config but in the Code during RunTime.
Create a new test console application, right click your project > Add > New Item > Devart Entity Model. Go through the Create Model Wizard, select database objects, choose the DbContext template (instead of default EntityObject), save the model to generate the code. Note: if you want to regenerate the code taking into account new changes in your model, you should just save the model. Now depending on the model settings the connection string in the code should look like this:

a) navigate to DbContext in Tools > Entity Developer > Model Explorer > the Templates node and set "Fluent Mapping=False" in its properties,
select designer surface and set the Metadata Artifact Processing property of EntityContextModel to Embed In Output Assembly.
As a result, there are no DataModel1.csdl / DataModel1.msl / DataModel1.ssdl files in the \bin\Debug folder because they are embedded into application assembly.

Code: Select all

var context = new TESTModel.TESTEntities(@"metadata=res://*/DataModel1.csdl|res://*/DataModel1.ssdl|res://*/DataModel1.msl;provider=Devart.Data.PostgreSql;provider connection string=""user id=postgres;password=postgres;host=db;port=5441;database=test;persist security info=True""");
b) DbContext's Fluent Mapping=False,
EntityContextModel's Metadata Artifact Processing=Copy To Output Directory.
As a result, DataModel1.csdl / DataModel1.msl / DataModel1.ssdl are created in the \bin\Debug folder.

Code: Select all

var context = new TESTModel.TESTEntities(@"metadata=DataModel1.csdl|DataModel1.ssdl|DataModel1.msl;provider=Devart.Data.PostgreSql;provider connection string=""user id=postgres;password=postgres;host=db;port=5441;database=test;persist security info=True""");
c) DbContext's Fluent Mapping=True,
EntityContextModel's Metadata Artifact Processing=Do Not Generate Mapping Files.

Code: Select all

DbProviderFactory factory = DbProviderFactories.GetFactory("Devart.Data.PostgreSql");
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = @"user id=postgres;password=postgres;host=db;port=5441;database=test;persist security info=True";
var context = new TESTModel.TESTEntities(connection, true);
snmigerl wrote:Schema specified is not valid. Errors:
Devart.Data.PostgreSql.Entity.ProviderManifest.StoreSchemaDefinition.ssdl
The EntityContainer name must be unique. [...]
Please give us the following information:
a) the exact version of your target PostgreSQL server
b) the value of the Provider Manifest Token property of your EntityContextModel
c) in the debug mode when the error occurs, navigate to the Debug > Windows > Modules window of Visual Studio and tell us the full paths of all Devart.Data.PostgreSql.Entity.dll and EntityFramework.dll assemblies loaded to the process of your application.

Post Reply