我有一个解决方案,可以通过c#的数据表批量加载数据,如下所示:
private void LoadRemittanceLines(DataTable dt, EiseBEDbEntities context)
{
var param = new SqlParameter("Payments", SqlDbType.Structured)
{
Value = dt,
TypeName = "dbo.udtRAPayment",
Direction = ParameterDirection.Input
};
var r = context.Database.ExecuteSqlCommand("EXEC spRAPaymentInsertBulk", param);
}
该行触发,没有错误,但是该表未产生任何结果。我分析了我的Db,并捕获了执行的代码。这是一个蒙版的摘要示例:
--THIS IS ADDED BY ME TO CLEAR THE TABLE
delete from EiseBEDb..RAPayment
declare @p3 dbo.udtRAPayment
insert into @p3 values(1234879,987654,1,123.49,'2017-09-20 00:00:00','2017-09-20 00:00:00',NULL,0,'2018-07-22 00:00:00',10,0,NULL,NULL,1,N'This is a long string',NULL,NULL,NULL,N'',N'',N'1234',N'','2017-09-12 00:00:00',NULL,NULL)
--THIS CODE YIELDS RESULTS
--EXEC spRAPaymentInsertBulk @Payments=@p3
--THIS CODE YIELDS NO RESULTS
exec sp_executesql N'EXEC spRAPaymentInsertBulk',N'@Payments [dbo].[udtRAPayment] READONLY',@Payments=@p3
--THIS IS ADDED BY ME TO CHECK THE DATA
select * from EiseBEDb..RAPayment
我想念的是什么,我有办法通过吗?我能想到的唯一解决方案是不使用EF传递我的数据,而只是建立与Db的连接,手动结束调用该工作代码行。
这里是spRAPaymentInsertBulk,由于机密性,字段名被省略。
CREATE PROCEDURE [dbo].[spRAPaymentInsertBulk]
(
@Payments udtRAPayment readonly
)
AS
begin
insert into RAPayment (Field1, field2)
select Field1, field2
from @Payments p
end
我正在使用SQL Server 2017。
答案 0 :(得分:0)
我的问题是我通过的文字,此问题得以解决:
var r = context.Database.ExecuteSqlCommand("exec spRAPaymentInsertBulk @Payments", param);