我通过 ODBC 提供程序在 C# 中使用 Insight.Database 连接到 iSeries DB2 数据库。db2 中有一个名为 InsertBeer 的存储过程。以下所有调用都很好用!:
List<Beer> beers = conn.QuerySql<Beer>("SELECT * FROM Beer WHERE Typee = @Typee", new { Typee = "IPA" }).ToList();
var beer = new Beer { ID=41,Typee="Medium", Description = "From dotNet Neither light or dark"};
conn.ExecuteSql("INSERT INTO Beer VALUES (@ID, @Typee, @Description)", new { ID = 4, Typee = "Medium", Description = "From dotNet Neither light or dark" });
conn.ExecuteSql("CALL INSERTBEER (@ID, @Typee, @Description) ", new { ID = 4, Typee = "MediumOD", Description = "From dotNet Neither light or dark" });
conn.ExecuteSql("INSERT INTO Beer VALUES (@ID, @Typee, @Description)", beer);
太棒了,我真的在挖掘这个微 ORM。已经赢了一半的战斗,上面调用的啤酒对象节省了大量的手动参数绑定。但我不想在调用 InsertBeer 存储过程时输入 LHS 参数。我相信这是 Insight Execute() 方法旨在避免的管道工作类型。可悲的是,这些调用不起作用:
conn.Execute("INSERTBEER", beer);
我也试过:
conn.Execute("insertbeer", new Beer {ID = 4, Typee = "Medium", Description = "From dotNet Neither light or dark"}, CommandType.StoredProcedure, true, Int32.MaxValue, null, beer);
我得到的错误是:
{“错误 [42000] [IBM][System i Access ODBC 驱动程序][DB2 for i5/OS]SQL0104 - 令牌 INSERTBEER 无效。有效令牌:(CL END GET SET CALL DROP FREE HOLD LOCK OPEN WITH。”}
任何想法都非常感谢!