Click here to Skip to main content
15,867,330 members
Articles / Database Development / PostgreSQL
Tip/Trick

Entity Framework 2.1 - npg PostgreSql Error

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
17 Feb 2019CPOL 6.2K   1  
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:

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Program Manager
Jordan Jordan
Self-motivated, creative and results-driven technology executive who is well versed and experienced in leveraging an end-to-end, holistic vision of business objectives to drive full technology / business alignment.

Skilled in grasping business needs and sudden market demand’s shifts by diving into latest business / technology trends, selecting the best fit business model / technology to create a positive reflection on revenue. His multifaceted approach has enabled him to deliver key solutions across a wide range of disciplines including design, development, UX / UI, Business Intelligence.

Technical Specialties are in .Net, Java, Spring Boot, Maven, MS SQL, Oracle, Postgesql, Redis, Javascript, Bootstrap, Angular 2.

Comments and Discussions

 
-- There are no messages in this forum --