65.9K
CodeProject is changing. Read more.
Home

Entity Framework 2.1 - npg PostgreSql Error

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Feb 17, 2019

CPOL
viewsIcon

6561

PostgreSQL exception 42P01

Introduction

While using npg package as your data store ORM, you are expecting the ORM framework (Entity Framework in our case) to generate the SQL statement ... you might face a PostgreSQL exception that the relation 'Table Name' does not exist ... either the table is not created or the generated SQL statement is missing something.

Resolution

Try to debug using Visual Studio. You will see that the schema name is not leading the table name ... SELECT "ID", "Name", "CreatedBy", "CreatedDate" FROM "TestTable"; while PostgreSQL is expecting the schema name ... Resolution is in the DBContext class override the OnModelCreating method and add modelBuilder.HasDefaultSchema("SchemaName"); and execute the base constructor which should look like the following:

 protected override void OnModelCreating(ModelBuilder modelBuilder)
         {
             modelBuilder.HasDefaultSchema("PartyDataManager");
             base.OnModelCreating(modelBuilder);
         }