PetaPoco的语法返回已删除记录的列表(来自PostgreSQL)?

时间:2016-10-29 19:32:08

标签: petapoco

我有工作的PostgreSQL(9.5)删除声明:

delete from dx d using patients p 
where p.chart_recid = d.chart_recid 
and p.recid = 15478 and d.icd9_recid = 7574
returning d.recid

使用PetaPoco的正确电话是什么? (我试图从中返回一个int列表 删除声明)。可以吗?

编译:

List<int> deleted = db.Execute(PetaPoco.Sql.Builder
                    .Append("delete from dx d ")
                    .Append("using patients p ")
                    .Append("where p.chart_recid = d.chart_recid ")
                    .Append("and p.recid = @0 and d.icd9_recid = @1 ", (int)patient_recid, (int)icd9_recid)
                    .Append("returning d.recid")
                    );
                return deleted;

TIA

解决方案:这适用于PetaPoco stored procedure error “Incorrect syntax near the keyword 'FROM'.”}

的赞美
List<int> deleted = db.Fetch(PetaPoco.Sql.Builder
                    .Append(";delete from dx d ")
                    .Append("using patients p ")
                    .Append("where p.chart_recid = d.chart_recid ")
                    .Append("and p.recid = @0 and d.icd9_recid = @1 ", (int)patient_recid, (int)icd9_recid)
                    .Append("returning d.recid")
                    );
                return deleted;

1 个答案:

答案 0 :(得分:0)

Db.Execute()调用ExecuteNonQuery方法并在异常时返回受影响的行或(-1)。我认为应该是;

int deleted = db.Execute(PetaPoco.Sql.Builder
                    .Append("delete from dx d ")
                    .Append("using patients p ")
                    .Append("where p.chart_recid = d.chart_recid ")
                    .Append("and p.recid = @0 and d.icd9_recid = @1 ", (int)patient_recid, (int)icd9_recid)
                    .Append("returning d.recid")
                    );
                return deleted;