我正在使用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
而不是表名。
是否有人遇到过相同的错误?我可能错过了某些设置吗?