- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Npgsql EF6 提供程序 (Npgsql v3.0.5.0)。我从现有数据库生成模型。我可以访问数据库并读取记录,但更新现有记录失败。
这是我的代码的简化版本:
int jobId = 123; // some unique id
Entities entities = new Entities();
Job job = entities.Jobs.First(j => j.Id = jobId);
job.Status = 4;
entities.SaveChanges(); // this line throws an exception
这是我从这段代码中得到的错误信息:
42601: syntax error at or near "("
[NpgsqlException (0x80004005): 42601: syntax error at or near "("]
Npgsql.NpgsqlConnector.DoReadSingleMessage(DataRowLoadingMode dataRowLoadingMode, Boolean returnNullForAsyncMessage, Boolean isPrependedMessage) +445
Npgsql.NpgsqlConnector.ReadSingleMessage(DataRowLoadingMode dataRowLoadingMode, Boolean returnNullForAsyncMessage) +282
Npgsql.NpgsqlCommand.Execute(CommandBehavior behavior) +270
Npgsql.NpgsqlCommand.ExecuteNonQueryInternal() +177
Npgsql.NpgsqlCommand.ExecuteNonQuery() +21
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext`1 c) +26
System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +129
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext) +602
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery() +151
System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues) +1045
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +221
这是针对数据库运行的查询:
UPDATE (
SELECT
"Jobs"."Id",
"Jobs"."Name",
"Jobs"."Created",
"Jobs"."Status"
FROM "Jobs"."Jobs"
AS "Jobs"
) SET "Status"=$1 WHERE "Id" = $2
我知道这个查询显然不适用于嵌套的 SELECT
而不是表名。
有人遇到过同样的错误吗?有没有我可能会错过的设置?
最佳答案
此错误是由受影响表上的缺少主键引起的。
.edmx
文件实际上包含以下消息:
warning 6002: The table/view '[database.schema.TableName]' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.
当从数据库更新模型时,Visual Studio 还在输出选项卡中显示以下消息(我一定是在第一次生成模型时错过了):
The model was generated with warnings or errors.ServiceModel.edmxPlease see the Error List for more details. These issues must be fixed before running your application.
关于entity-framework - Npgsql 的 EntityFramework6 创建无效的更新语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36143470/
如果没有正确设置项目,总会出现这样的错误: 无法加载文件或程序集“Npgsql,版本 = 3.1.2.0,文化 = 中立,PublicKeyToken = 5d8b90d52f46fda7”或其依赖项
我正在尝试将 TransactionScope 与 Npgsql 提供程序一起使用。 我在一个旧问题 ( provider for PostgreSQL in .net with support fo
添加到我的 vs2015 update 3 安装中。到一个全新的控制台项目。 Attempting to gather dependency information for package 'Npgs
我正在尝试将数据从 PostgreSQL 数据库获取到 PowerBI Desktop,但似乎不起作用。我认为问题出在 npgsql 的安装上。当尝试在 PowerBI 中设置新的数据库连接时,我输入
我是 C# 的新手。我在下面的 .UseNpgsql(string connectionString) 上看到了一些红色波浪线(错误下划线)。悬停错误告诉我,我可能没有使用正确的 using 语句。
我正在使用 NLog4.1 版本进行日志记录。 我的“NLog.config”看起来像: PRODUCTION INSERT INTO "MY"."LOG_TABL
我有一个使用 PostgreSQL 并使用 Npgsql 作为数据驱动程序的 ASP.NET 应用程序。我时不时地收到这个错误: Could not load file or assembly 'Np
我正在尝试从 NPGSQL v2.0.11 迁移到 v3.1.7 但是在我的代码中我正在访问 NpgsqlException 的代码属性。在 3.1.7 中,这已经消失了;我现在如何从 postgre
我想将现有的事件实现替换为可以在事件进入时处理事件的实现,如有必要,可以同时处理。不幸的是,我以前从未实现过任何类型的并发,但必须从某个地方开始,嗯? 我一直在阅读 Functional Reacti
当我在我的连接字符串中使用 Pooling=True 时,出现错误“无法在恢复期间执行不监听”。 此错误发生在热备运行的复制/读取服务器上。 最佳答案 这在 3.2.7 版本中仍然存在。应该可以在热备
背景:我正在将我的应用程序从 mssql 移动到 npgsql v2.0.11.92。 运行我的应用程序几分钟或几小时后,我得到一个 System.Exception:从池中获取连接时超时 . 我在
我目前正在开发一个具有 PostgreSQL 后端的 .Net 应用程序。我正在使用 NpgSQL 来连接两者。当我尝试进行简单的数据检索时,NpgSQL 返回以下错误: 42601: syntax
我正在尝试将 Postgres 中的 timestamp[] 字段类型与 NPGSQL 一起使用,这样我就可以在我的 Entity Framework 模型中使用 DateTime[] 类型。 我已将
我使用 PostgreSQL/NpgSQL 将 c# 桌面应用程序连接到 PostgreSQL 数据库。第一个任务是返回我数据库中的所有表名,这工作正常。根据这个结果,我想获取每个表的所有列名。但问题
我们正在为多人游戏开发数据库后端。服务器用 C# 编写,并通过 Npgsql 与 Postgres 数据库对话。 现在,手册展示了如何使用准备好的语句: NpgsqlCommand command =
这可能与我在 FNH 遇到的其他问题有某种联系。 Fluent NHibernate cannot load MySql.Data from GAC in debug mode of a test 通
我无法在程序启动时可靠地检查 NET/Npgsql 中的数据库是否存在。 代码如下: Public Function dbExists(ByVal _dbName As String) As Bool
我编写了一个基本脚本,可将数据从 PostgreSQL 数据库同步到另一个系统,该脚本在我的测试/开发环境中执行时没有问题,使用: PostgreSQL 9.4 Npgsql dll 版本 3.0.3
这是手册中给出的示例。当我尝试同样的操作时,我得到了无数的异常(exception)。这有什么错误。 using(NpgsqlConnection conn = new NpgsqlConnectio
我正在尝试创建一个包含文件路径的记录。使用 NpqSQL 驱动程序插入启用 UTF8 的 Postgres 数据库。 我的表格定义: CREATE TABLE images ( id seri
我是一名优秀的程序员,十分优秀!