Column Extent1.Id does not exist in Mono with Entity Framework 6 and PostgreSQL

风流意气都作罢 提交于 2019-12-04 05:14:54

问题


I am trying to map to a PostgreSQL database with Entity Framework using the packages Npsql and Npsql.EntityFramework. I have a database with the following table:

CREATE TABLE IF NOT EXISTS Crops (
  Id            INT PRIMARY KEY     NOT NULL,
  Name          TEXT                NOT NULL,
  SowingMonths  INT
);

The Crop model looks as follows:

public class Crop
{
    public int Id { get; set; }
    public string Name { get; set; }
    public Month SowingMonths { get; set;} //Month is an enum
}       

In the database context I map the schema to public since all tables are in the schema public by default in PostgreSQL.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.HasDefaultSchema("public");
}

Now when I open the view that tries to access Crops of the DbContext I get this message:

Npgsql.NpgsqlException
ERROR: 42703: column Extent1.Id does not exist
Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): Npgsql.
Exception stack trace:
at Npgsql.NpgsqlState+d__0.MoveNext () [0x00000] in :0 at Npgsql.ForwardsOnlyDataReader.GetNextResponseObject (Boolean cleanup) [0x00000] in :0

The good news is the database can find the table now (it could not at first, but it can with the mapping to the public schema in the OnModelCreating method). However, it cannot find the column name Extend.Id.

Why it tries to look for Extend.Id is beyond me. We have defined the property on the Crops model as Id, why then does it look for Extend.Id? But considering this is the case, how can I get this to work? Can I just create a database table with a property Extend1.Id instead of Id? And if so, how do I do it?

Thank you!


回答1:


I'm convinced that there is a typographical error somewhere in your code. The table "Id" simply does not exist. Capital letters maybe?



来源:https://stackoverflow.com/questions/26948688/column-extent1-id-does-not-exist-in-mono-with-entity-framework-6-and-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!