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

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

问题描述

我正在尝试使用包 Npsql<映射到带有实体框架的 PostgreSQL 数据库/code>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
);

Crop 模型如下所示:

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.错误处理请求.
详细信息:非 Web 异常.异常来源(应用程序或对象的名称):Npgsql.
异常堆栈跟踪:
在 Npgsql.NpgsqlState+d__0.MoveNext () [0x00000] in :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 开始,但它可以在 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 超出了我的理解.我们已经将 Crops 模型的属性定义为 Id,那它为什么要查找 Extend.Id?但考虑到这种情况,我怎样才能让它工作呢?我可以只使用属性 Extend1.Id 而不是 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?

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

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