将多个图像 url 分配给存储在 sql 服务器数据库中的项目
assigning multiple image urls to an item stored in sql server database
我正在使用 asp.net 核心剃须刀页面构建一个在线购物网站,目前我的 sql 数据库中只有一个变量 table 接受一个字符串作为图像名称,但是图像存储在图像文件夹的根目录中。这是我的模型
public class GasContainer
{
public int GasContainerId { get; set; }
public string Name { get; set; }
public string Weight { get; set; }
public string Color { get; set; }
public string Image { get; set; }
public double Price { get; set; }
public double Discount { get; set;}
[NotMapped]
public double DiscountedPrice => Price - Discount;
//public decimal Price { get; set; }
public enum EColor
{
Red = 0,
Yellow = 1,
Green = 2,
Blue = 3,
Gray = 4
};
public string Type { get; set; }
public int? BrandId { get; set; }
public Brand Brand { get; set; }
}
我希望每个气体容器都有多个与之关联的图像路径。由于 sql 服务器不接受数组作为数据类型,我该如何处理?
我终于明白怎么...
添加另一个与 GasContainer(一对多关系)相关的 table,例如 GasContainerImages table 和 imageurl 属性,将上传的文件复制到您选择的文件夹并更新图像 url GasContainerImages 的字符串指向包含图像的文件夹
我正在使用 asp.net 核心剃须刀页面构建一个在线购物网站,目前我的 sql 数据库中只有一个变量 table 接受一个字符串作为图像名称,但是图像存储在图像文件夹的根目录中。这是我的模型
public class GasContainer
{
public int GasContainerId { get; set; }
public string Name { get; set; }
public string Weight { get; set; }
public string Color { get; set; }
public string Image { get; set; }
public double Price { get; set; }
public double Discount { get; set;}
[NotMapped]
public double DiscountedPrice => Price - Discount;
//public decimal Price { get; set; }
public enum EColor
{
Red = 0,
Yellow = 1,
Green = 2,
Blue = 3,
Gray = 4
};
public string Type { get; set; }
public int? BrandId { get; set; }
public Brand Brand { get; set; }
}
我希望每个气体容器都有多个与之关联的图像路径。由于 sql 服务器不接受数组作为数据类型,我该如何处理?
我终于明白怎么... 添加另一个与 GasContainer(一对多关系)相关的 table,例如 GasContainerImages table 和 imageurl 属性,将上传的文件复制到您选择的文件夹并更新图像 url GasContainerImages 的字符串指向包含图像的文件夹