C# 插入记录时使用Excel导入实体框架
我正在使用nopcommerce 1.9,在创建折扣时,我有以下代码C# 插入记录时使用Excel导入实体框架,c#,entity-framework,import-from-excel,C#,Entity Framework,Import From Excel,我正在使用nopcommerce 1.9,在创建折扣时,我有以下代码 discount = new Discount() { DiscountTypeId = (int)discountType, DiscountRequirementId = (int)discountRequirement, RequirementSpentAmount = requirementSpent
discount = new Discount()
{
DiscountTypeId = (int)discountType,
DiscountRequirementId = (int)discountRequirement,
RequirementSpentAmount = requirementSpentAmount,
RequirementBillingCountryIs = requirementBillingCountryIs,
RequirementShippingCountryIs = requirementShippingCountryIs,
DiscountLimitationId = (int)discountLimitation,
LimitationTimes = limitationTimes,
Name = name,
UsePercentage = usePercentage,
DiscountPercentage = discountPercentage,
DiscountAmount = discountAmount,
StartDate = discountStartDate,
EndDate = discountEndDate,
RequiresCouponCode = requiresCouponCode,
CouponCode = couponCode
};
this.DiscountService.InsertDiscount(discount);
现在我的任务是在'CouponCode=CouponCode'
中,我必须替换客户保存折扣时上传的excel表单列中的优惠券代码
这个excel表格可以有50000个优惠券代码,所以每个优惠券都有相同的折扣信息
在这个解决方案中,我们有实体框架。我们必须以这种格式存储数据
D1 10% C1(coupon code from excel sheet)
D1 10% C2(coupon code from excel sheet)
D1 10% C3(coupon code from excel sheet)
D1 10% C4(coupon code from excel sheet)
D1 10% C5(coupon code from excel sheet)
D1 10% C6(coupon code from excel sheet)
D1 10% C7(coupon code from excel sheet)
我找到了用这种方式处理这种情况的方法。我仍然必须循环每个记录,但我认为这是我工作的必要性 你能解释一下问题是什么吗?我不得不通过更改excel中的couponcode=数据多次删除此代码
if (fuXlsFile.PostedFile != null && !String.IsNullOrEmpty(fuXlsFile.FileName))
{
DataTable dt = GetDataFromExcel(filePath, "Sheet1");
foreach (DataRow dr in dt.Rows)
{
discount = new Discount()
{
DiscountTypeId = (int)discountType,
DiscountRequirementId = (int)discountRequirement,
RequirementSpentAmount = requirementSpentAmount,
RequirementBillingCountryIs = requirementBillingCountryIs,
RequirementShippingCountryIs = requirementShippingCountryIs,
DiscountLimitationId = (int)discountLimitation,
LimitationTimes = limitationTimes,
Name = name,
UsePercentage = usePercentage,
DiscountPercentage = discountPercentage,
DiscountAmount = discountAmount,
StartDate = discountStartDate,
EndDate = discountEndDate,
RequiresCouponCode = requiresCouponCode,
CouponCode = dr[0].ToString()
};
this.DiscountService.InsertDiscount(discount);
}
}