大家好,我使用由 code smith 工具生成的实体框架,我遇到了批量更新的问题。因为我在网格中有很多行,我想使用批量更新来更新记录。我试图这样做但没有成功我的代码如下
try
{
TList<PriceSystemItems> _priceSystemCollection = new TList<PriceSystemItems>() ;
for (int i = 0; i < gvService.Rows.Count; i++)
{
_priceSystemItems = new PriceSystemItems();
EntityDropDownList dataServiceTypeId = (EntityDropDownList)gvService.Rows[i].FindControl("dataServiceTypeId1");
EntityDropDownList dataPricePlanId = (EntityDropDownList)gvService.Rows[i].FindControl("dataPricePlanId1");
EntityDropDownList dataNoMatchPlanId = (EntityDropDownList)gvService.Rows[i].FindControl("dataNoMatchPlanId1");
EntityDropDownList dataSurchargePlanId = (EntityDropDownList)gvService.Rows[i].FindControl("dataSurchargePlanId1");
CheckBox chkDefault = (CheckBox)gvService.Rows[i].FindControl("chkDefault");
Label lblPricePlanId = (Label)gvService.Rows[i].FindControl("lblPricePlanId");
_priceSystemItems.ServiceTypeId = int.Parse(dataServiceTypeId.SelectedValue);
_priceSystemItems.PriceSystemId = _priceSystemId;
_priceSystemItems.NoMatchAltPlanId = int.Parse(dataNoMatchPlanId.SelectedValue);
_priceSystemItems.SurchargePlanId = int.Parse(dataSurchargePlanId.SelectedValue);
_priceSystemItems.IsDefault = chkDefault.Checked;
_priceSystemItems.PricePlanId = int.Parse(lblPricePlanId.Text);
_priceSystemItems.OriginalPriceSystemId = _priceSystemId;
_priceSystemItems.OriginalServiceTypeId = int.Parse(dataServiceTypeId.SelectedValue);
_priceSystemCollection.Add(_priceSystemItems);
}
_priceSystemItemsService.Update(_priceSystemCollection);
}
catch (Exception /*ex*/)
{
}