The npgsql schema "dbo" does not exist

I have a problem similar to Entity Framework 5.0 PostgreSQL (Npgsql) factory default connection

I have Npgsql declared in app.config:

<connectionStrings> <add name="monDbContexte" connectionString="Server=127.0.0.1;Port=5432;Database=ma_datab_db;User Id=postgres;Password=root;" providerName="Npgsql" /> </connectionStrings> <!-- le factory provider --> <system.data> <DbProviderFactories> <add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql" /> </DbProviderFactories> </system.data> </configuration> 

my context provider class:

 public class ContextDB: DbContext { public DbSet<Personne> Personnes { get; set; } public ContextDB() : base("monDbContexte") { } } 

my class is "Personne":

[Table ("personnes", Schema = "public")] public class Personne {[Key] [Column ("id_personne")] [Display (Name = "Identifiant")] public int id {get; set; }

  [Column("nom")] [Display(Name = "Nom")] [Required(ErrorMessage = "Merci de saisir le nom.")] public string Nom { get; set; } [Column("prenom")] [Display(Name = "Prénom")] [Required(ErrorMessage = "Merci de saisir le prénom.")] public string Prenom { get; set; } ... ... } 

and in my management I am doing something like this:

  using (var context = new ContextDB()) { // *** here i have an exception... var personnes = from p in context.Personnes where p.Nom.StartsWith("m") orderby p.Nom select new { p.Nom, p.Prenom }; foreach (var une_personne in personnes) { Console.WriteLine(une_personne.Nom + " " + une_personne.Prenom); } 

after that I have an exception:

 ERROR: schema "dbo" does not exist 

this is an NpgsqlException exception

[French]
ERREUR: 3F000: le schéma "dbo" n'existe pas

I don't know what's wrong with that

EDIT:

This is an exception:
(sorry, but this is in french)

PS: I do not have projects in " C: \ projects \ Npgsql2 ", and I have nothing like this in my current project, so what is it?

 L'exception Npgsql.NpgsqlException n'a pas été gérée par le code utilisateur HResult=-2147467259 Message=ERREUR: 3F000: le schéma « dbo » n'existe pas Source=Npgsql ErrorCode=-2147467259 BaseMessage=le schéma « dbo » n'existe pas Code=3F000 Detail="" ErrorSql=SELECT "GroupBy1"."A1" AS "C1" FROM (SELECT CAST (count(1) AS int4) AS "A1" FROM "dbo"."__MigrationHistory" AS "Extent1Group") AS "GroupBy1" File=src\backend\catalog\namespace.c Hint="" Line=2826 Position=82 Routine=get_namespace_oid Severity=ERREUR Where="" StackTrace: à Npgsql.NpgsqlState.<ProcessBackendResponses_Ver_3>d__a.MoveNext() dans C:\projects\Npgsql2\src\Npgsql\NpgsqlState.cs:ligne 850 à Npgsql.ForwardsOnlyDataReader.GetNextResponseObject() dans C:\projects\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:ligne 1173 à Npgsql.ForwardsOnlyDataReader.GetNextRowDescription() dans C:\projects\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:ligne 1191 à Npgsql.ForwardsOnlyDataReader.NextResult() dans C:\projects\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:ligne 1377 à Npgsql.ForwardsOnlyDataReader..ctor(IEnumerable`1 dataEnumeration, CommandBehavior behavior, NpgsqlCommand command, NotificationThreadBlock threadBlock, Boolean synchOnReadError) dans C:\projects\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:ligne 1040 à Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb) dans C:\projects\Npgsql2\src\Npgsql\NpgsqlCommand.cs:ligne 611 à Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior cb) dans C:\projects\Npgsql2\src\Npgsql\NpgsqlCommand.cs:ligne 588 à Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) dans C:\projects\Npgsql2\src\Npgsql\NpgsqlCommand.cs:ligne 538 à System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) à System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) InnerException: 
+4
source share
3 answers

It seems that EF uses dbo as the default schema for the database. You need to change it to "public", which is the default scheme for Postgresql.

You use this by importing a namespace:

 using System.ComponentModel.DataAnnotations; 

And annotate your classes to use a different scheme:

 [Table("mytable", Schema = "public")] Class test {...} 

For more information, check out your post on EF and Npgsql: http://fxjr.blogspot.com/2013/06/npgsql-code-first-entity-framework-431.html

Hope this helps.

+3
source

I had the same problem. I don’t know why, but when I did not use the Database.SetInitializer in Application_Start() method, this is just fine. So:

 //Database.SetInitializer<ContextDB>(new ContextDBInitializer()); 
0
source

My decision:

 public class PostgisDbContext : DbContext { public PostgisDbContext() : base("Postgis") { //begin try { this.Database.Initialize(false); issue } catch (Exception) {} //end } } 

It may be imperfect, but it works.

0
source

All Articles