![](/img/trans.png)
[英]PostgreSQL, Npgsql returning 42601: syntax error at or near “$1”
[英]error 42601 syntax near postgresql
我试图用实体框架和数据库 postgresql 保存数据
private OctopusDBEntities _dbContext;
public PendaftaranSiswaDA()
{
_dbContext = new OctopusDBEntities();
}
public resultVM SubmitFirstReg(resultVM model)
{
siswa_first_reg _tab_first_reg = new siswa_first_reg();
try
{
Mapper.CreateMap<FirstRegVM, siswa_first_reg>().ForAllMembers(cond => cond.Condition(src => !src.IsSourceValueNull));
_tab_first_reg = Mapper.Map(model.firstRegVM, _tab_first_reg);
_dbContext.Entry(_tab_first_reg).State = EntityState.Added;
_dbContext.SaveChanges(); // --- i have an error from here
model.isRegister = true;
model.message = "Data sudah terdaftar!";
}
catch (Exception e)
{
throw e;
}
return model;
}
这是由 entityframework 生成的查询。
INSERT INTO (SELECT siswa_first_reg.reg_no_registration, siswa_first_reg.reg_full_name, siswa_first_reg.reg_last_school_name, siswa_first_reg.reg_age, siswa_first_reg.reg_mobile_no, siswa_first_reg.reg_birth_place, siswa_first_reg.reg_birth_date, siswa_first_reg.reg_address, siswa_first_reg.reg_email, siswa_first_reg.reg_status, siswa_first_reg.reg_registration_date, siswa_first_reg.reg_gender FROM octo_test.siswa_first_reg AS siswa_first_reg) reg_no_registration, reg_full_name, reg_last_school_name, reg_age, reg_mobile_no, reg_birth_place, reg_birth_date, reg_address, reg_email, reg_status, reg_registration_date, reg_gender) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NULL, NULL, NULL, $9)
为什么这样生成查询? 我该怎么做才能解决它?
非常感谢。
我没有 OP 的答案,但这个问题确实让我意识到自己的错误。 尽管如果它实际上不包含原始查询,则异常通常非常无用,但很可能是查询格式/语法问题。 例如,我最近在 C# 代码中更改了一个查询以及其他一些内容,但是,我在参数列表中遗漏了一个逗号!
抱歉缺乏信息。 当我试图解决这个问题时,我找到了答案。
只是,想分享一下,也许有些人有同样的情况。 上面的代码没有错。 问题出在数据库上。 我没有在我的桌子上设置主键。
谢谢大家的关注和支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.