我正在尝试使用对存储过程的一次调用将多个记录插入到多个表中,然后调用插入到各个表中的相应存储过程。
我正在使用Insight.Database,它可以选择生成表值数据类型和存储过程,这些数据类型和存储过程将这些表值作为参数。因此,我认为我创建了自己的程序,该程序需要多个TVP并从此SP中调用生成的Insight.Database程序:
public Task<Int32> Migrate(IEnumerable<ProposalRow> proposals, String source, Func<Guid, Package> packageProvider)
{
List<CLIPFRow> clipf = new List<CLIPFRow>();
List<CLFPFRow> clfpf = new List<CLFPFRow>();
List<POLBAPFRow> polbapf = new List<POLBAPFRow>();
List<POL1PFRow> pol1pf = new List<POL1PFRow>();
List<POL2PFRow> pol2pf = new List<POL2PFRow>();
List<POL3PFRow> pol3pf = new List<POL3PFRow>();
List<POL4PFRow> pol4pf = new List<POL4PFRow>();
List<POL5PFRow> pol5pf = new List<POL5PFRow>();
List<POL6PFRow> pol6pf = new List<POL6PFRow>();
List<POL7PFRow> pol7pf = new List<POL7PFRow>();
List<POLBPFRow> polbpf = new List<POLBPFRow>();
List<POLGPFRow> polgpf = new List<POLGPFRow>();
List<POLQPFRow> polqpf = new List<POLQPFRow>();
List<POLSIPFRow> polsipf = new List<POLSIPFRow>();
foreach (var proposal in proposals)
{
clipf.AddRange(this.MapCLIPF(proposal, source));
pol1pf.Add(POL1PFRow.From(proposal, source));
polbapf.AddRange(POLBAPFRow.From(proposal, source));
pol2pf.AddRange(POL2PFRow.From(proposal, source));
pol3pf.AddRange(POL3PFRow.From(proposal, source));
pol4pf.AddRange(POL4PFRow.From(proposal, source));
pol5pf.AddRange(POL5PFRow.From(proposal, source));
pol6pf.AddRange(POL6PFRow.From(proposal, source));
if (proposal.Smi.StrategyPlans != null && proposal.Smi.StrategyPlans.Any())
{
pol7pf.AddRange(POL7PFRow.From(proposal, source));
}
if (proposal.Smi.Beneficiary != null)
{
polbpf.Add(POLBPFRow.From(proposal, source));
}
polgpf.AddRange(POLGPFRow.From(proposal, source));
if (proposal.Smi.Questionnaire != null && proposal.Smi.Questionnaire.Client != null)
{
polqpf.AddRange(POLQPFRow.From(proposal, source, packageProvider));
}
if (proposal.Smi.ProductMappingResult.BackOfficeProduct.BackOfficeProductCode.Equals("PUN4", StringComparison.InvariantCultureIgnoreCase))
{
polsipf.Add(POLSIPFRow.From(proposal, source));
}
clfpf.AddRange(CLFPFRow.From(proposal, source));
}
return base.DB.ExecuteAsync("usp_FOBO_InsertMany", new
{
CLIPF = clipf,
CLFPF = clfpf,
POLBAPF=polbapf,
POL1PF =pol1pf,
POL2PF =pol2pf,
POL3PF =pol3pf,
POL4PF =pol4pf,
POL5PF =pol5pf,
POL6PF =pol6pf,
POL7PF =pol7pf,
POLBPF =polbpf,
POLGPF =polgpf,
POLQPF =polqpf,
POLSIPF=polsipf
});
}
调用此过程的代码如下:
The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Table-valued parameter 7 (""), row 1, column 8: Data type 0xE7 has an invalid data length or metadata length.
The data for table-valued parameter "@CLIPF" doesn't conform to the table type of the parameter. SQL Server error is: 8037, state: 30
The statement has been terminated.
不幸的是,这给出了以下例外:
{{1}}
有什么想法吗?