列Extent1.Id不单与实体框架6和PostgreSQL存在 [英] Column Extent1.Id does not exist in Mono with Entity Framework 6 and PostgreSQL

查看:544
本文介绍了列Extent1.Id不单与实体框架6和PostgreSQL存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图映射到使用包PostgreSQL数据库实体框架 Npsql Npsql.EntityFramework 。我有以下表和数据库:

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
);



农作物模型如下所示:

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

在数据库方面,我的地图方案公开,因为所有的表都是在默认情况下,PostgreSQL的架构公众。

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");
}

现在,当我打开尝试访问的DbContext我得到的作物的看法此消息:

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

Npgsql.NpgsqlException结果错误:42703:列Extent1.Id不存在结果说明:HTTP 500。错误处理请求产品详细信息:非网络异常。异常原点(应用程序或对象的名称):Npgsql结果异常堆栈跟踪:在搜索+ Npgsql.NpgsqlState d__0.MoveNext()[0x00000]中:0在Npgsql.ForwardsOnlyDataReader.GetNextResponseObject(布尔清理)0x00000在0

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

好消息是,该数据库可以找到现在的表(可以的not~~V 在第一,但它可以在映射到公共架构在 OnModelCreating 方法)。但是,它无法找到列名 Extend.Id

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.

为什么它会尝试寻找 Extend.Id 我是无法理解。我们定义的作物属性模型编号,那么为什么它寻找 Extend.Id ?但考虑到这样的情况下,我怎么能得到这个工作?我可以创建的 Extend1.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?

感谢您!

推荐答案

我相信是有印刷错误的地方在你的代码。该表ID根本不存在。大写字母可能?

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

这篇关于列Extent1.Id不单与实体框架6和PostgreSQL存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆