最近看到论坛中很多人员在问调用webapi保存大批量数据时,提示超时“正在中止线程”的问题,报错如下:
response_error:{"InnerExWrapper":{"IsEmpty":false,"Data":{},"HelpLink":null,"Message":"正在中止线程。","Source":null,"StackTrace":" 在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
因为webapi的效率低,我的解决方式是采用BusinessDataServiceHelper.Save,具体代码如下
FormMetadata BillData = MetaDataServiceHelper.Load(ctx, "STK_TRANSFEROUT") as FormMetadata;
DynamicObject YsData = new DynamicObject(BillData.BusinessInfo.GetDynamicObjectType());
YsData["ID"] = 0;
YsData["DocumentStatus"] = "A";
YsData["CancelStatus"] = "A";
YsData["billno"] = billno;
DynamicObjectCollection Entitys = YsData["STK_STKTRANSFEROUTENTRY"] as DynamicObjectCollection;
for (int j = 0; j < drmx.Length; j++)
{
DynamicObject entity = new DynamicObject(Entitys.DynamicCollectionItemPropertyType);
entity["RowType"] = "Standard";
。。。。
}
IOperationResult result = BusinessDataServiceHelper.Save(ctx, BillData.BusinessInfo, new DynamicObject[] { YsData }, null, "Save");
执行效率很快
推荐阅读