c# - Pomelo 使用 MySQL 和 .NET Core 生成的 SQL 不正确
问题描述
我一直在使用 .NET Core 和 Pomelo.EntityFrameworkCore.MySql(v1.1.2,它不是最新的,但出于各种原因我更愿意继续使用它)。
我正在对模型类进行一些重构,创建子父关系(例如,订单有一个客户),现在当我运行我的项目时,我得到了一个异常
2019-09-16T12:36:49.8158085-07:00 0HLPQRKH27D40 [INF] Executed DbCommand (6ms) [Parameters=[],
CommandType='Text', CommandTimeout='0']
INSERT INTO `Order`
DEFAULT VALUES;
SELECT LAST_INSERT_ID(); (6438bdd5)
2019-09-16T12:36:49.9249074-07:00 0HLPQRKH27D40 [ERR] An exception occurred in the database while saving changes.
(3b5ca34b)
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT VALUES;
问题似乎是 in 的使用,default values
因为 insert into 'order' default values;
MySQL不支持该语法。我的 mysql 开发版本是 5.1,但这似乎无关紧要,因为它似乎不在更高版本中。
我(天真地)查看了 Pomelo 源代码,但只在单元测试中发现了“默认值”的用法。
解决方案
我正在按顺序将属性映射到另一个对象的属性,例如
public string PropA => obj.ProbA
当我停止这样做并使用 getter 和 setter 将其更改为长格式时,它开始工作。
推荐阅读
- node.js - 从'mssql'导入sql;控制台.log(sql); // 返回未定义
- git - Git Pull 清除了我本地目录中的所有内容
- android - 如何在 Splashscreen API 中删除我的启动画面图标周围的圆形遮罩?
- java - 通过 jpackage 打包找不到或加载主类
- c - C:在动态分配的内存中插入比初始化更多的元素
- html - 在卡片引导程序中保持相同的内容高度
- php - 让 PHP 路由库与 Azure 应用服务一起使用?
- vuejs2 - 在 vue.js 中自定义 Vuetify 深色主题背景的背景(不是 Nuxt!)
- javascript - 如何解决 VSC 错误“ENOENT:没有这样的文件或目录”?
- python - Tkinter - 如何动态调整渐变帧的大小?