c# - 无法更新多个表中的 Isactive 标志状态
问题描述
我有模型课
public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public bool IsActive { get; set; }
public virtual ICollection<ProductSKU> ProductSKUs { get; set;
}
public class ProductSKUResponse
{
public int Skuid { get; set; }
public String Sku { get; set; }
public decimal MRP { get; set; }
public bool IsActive { get; set; }
}
我想更新isactive
多个表中的状态,但我没有找到解决方案,所以恳请您让我知道逻辑。
public async Task<ReturnBoolean> DeleteProductById(int Id, bool status)
{
ReturnBoolean response = new ReturnBoolean();
Contracts.Entities.Product product = await _productRepository.GetByIdAsync(Id);
if (product == null)
{
throw new ArgumentException("Unable to delete selected product, product does not exist");
}
product.IsActive = status;
product.UpdatedOn = DateTime.Now;
product.ProductSKUs = await productSkuRepository.GetProductSkus(Id);
// from this onwards I didn't understand how to assign status value to in product.ProductSKUs.isactive.
await _productRepository.UpdateAsync(product, true);
response.BooleanValue = true;
return response;
}
解决方案
尝试简单的 foreach
foreach(ProductSKU productSKU in product.ProductSKUs.ToList())
{
productSKU.IsActive = status;
}
但是也要看这个方法是怎么实现的_productRepository.UpdateAsync(product, true)
推荐阅读
- forms - 如何将从相机拍摄的图像添加到列表视图?Xamarin 表单
- mysql - 如何显示表中的一半记录?MYSQL
- python-3.x - BrokenPipeError:[Errno 32] Windows 和 CUDA 10 上的管道损坏
- wpf - 如何调整 ValidationErrorTemplate 边框的宽度?
- perl - 通过 SSH 转义 RSYNC 的错误服务器路径
- onelogin - 是否可以在自定义登录页面上使用社交登录功能?
- javascript - 在不重新加载的标签之间切换并限制打开具有相同 URL 的新标签
- entity-framework - 我可以将影子属性用于属性子项吗?
- python - 使用 Python 在 Mac 上打开应用程序
- java - 垂直合并单元格并将数据插入单元格