【发布时间】:2018-11-02 02:13:03
【问题描述】:
我必须使用 Dapper 添加一个对象列表。
Dapper 动态参数抛出 SQLException “必须定义标量变量”是我在数据库中成功创建第一个对象后收到的错误。
这是cs:
public class Inventorytransaction
{
//InventoryHeader
public int id { get; set; }
public int transactionumber { get; set; }
public string storeroom { get; set; }
public string transactiontype { get; set; }
public string projectname { get; set; }
public string comments { get; set; }
public DateTime date { get; set; }
//InventoryLine
public string locationtype { get; set; }
public string lc { get; set; }
public string itemnum { get; set; }
public decimal quantity { get; set; }
public string uom { get; set; }
public decimal unitprice { get; set; }
下面是调用该过程的代码:
public void AddInventoryTransaction(Inventorytransaction inventorytransaction)
{
{
List<Inventorytransaction> inventorytransactions = new List<Inventorytransaction>();
inventorytransactions.Add(inventorytransaction);
using (IDbConnection connection = new SqlConnection(_connectionString))
{
//TODO
connection.Execute("dbo.spAddNewInventoryHeader @Storeroom, @Transactiontype,@Projectname, @Comments", inventorytransaction);
}
}
}
public void AddInventoryTransactionLine(Inventorytransaction inventorytransaction)
{
List<Inventorytransaction> inventorytransactions = new List<Inventorytransaction>();
inventorytransactions.Add(inventorytransaction);
using (IDbConnection connection = new SqlConnection(_connectionString))
{
//TODO
connection.Execute("dbo.spAddNewInventoryLine @Storeroom, @Locationtype,@Lc, @Itemnum,@Quantity,@Uom,@Unitprice", inventorytransaction);
}
}
这是界面:
interface IInventorytransactionRepository
{
void List<AddInventoryTransaction>();
}
有谁知道我做错了什么?使用这种方法,我可以在数据库中创建一个插入,但不能再创建一个。
【问题讨论】:
-
您没有使用您创建的
List。或者您没有发布所有代码。 -
这是代码。你能举个例子吗?我现在挣扎了一段时间:)
-
我想通了 :) 谢谢。你是对的