Sybase ASE Entity Framework - 将记录更新到数据库时出错 - “'('.\n”附近的语法不正确
我正在尝试简单地更新现有记录。我收到错误 - '('附近的语法不正确。\n
Entities db = new Entities();
try
{
var existingObj = new OBJETE
{
OB_ID_MR = 348,
OB_ID_JE = 1156,
OB_IS_NT = false,
OB_ID_MS = 88,
OB_POSITIONABS = "12,12,12,12",
OB_ORDRE = 1,
OB_UPDATEDATE = DateTime.Now
};
db.OBJETEs.Attach(existingObj);
db.ObjectStateManager.ChangeObjectState(existingObj, System.Data.EntityState.Modified);
db.SaveChanges();
如果我尝试更新“not null”列,那么我可以更新此表中的记录。但是当我尝试更新时如果可以为空值,那么我会一直收到此错误,请提出建议。
I am trying to simple update and existing record. And I am getting the error - incorrect syntax near '('.\n
Entities db = new Entities();
try
{
var existingObj = new OBJETE
{
OB_ID_MR = 348,
OB_ID_JE = 1156,
OB_IS_NT = false,
OB_ID_MS = 88,
OB_POSITIONABS = "12,12,12,12",
OB_ORDRE = 1,
OB_UPDATEDATE = DateTime.Now
};
db.OBJETEs.Attach(existingObj);
db.ObjectStateManager.ChangeObjectState(existingObj, System.Data.EntityState.Modified);
db.SaveChanges();
If I try to update "not null" columns then I can update the records in this table. But when I try to update nullable values then I am getting this error consistently. Please advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了!我的表没有主键。实体框架添加一些附加标签来禁用此类表的更新。
因此,要么向表添加主键,要么如果这不是像我这样的选项,解决方法是在文本模式下打开 edmx 文件,并删除标签的条目 - “DefiningQuery”及其所有内容有问题的表。另外我们需要改变 =>该表的 store:Schema="dbo" 到 Schema="dbo"。这应该可以解决问题。
Found it! My Table did not have a Primary Key. Entity Framework add some addition tag to disable update of such tables.
So either you add a primary key to the table or if that is not an option like in my case the work around is to open the edmx file in Text mode, and remove the entry for the tag - "DefiningQuery" and all its contents for the Table in question. Additionally we need to change => store:Schema="dbo" to Schema="dbo" for that Table. This should fix the issue.