我正在从“pro asp.net mvc3”一书中构建sportsstore应用程序。在第9章中,我必须添加图像上传功能。我更新了我的域对象“产品”,并将列添加到我的数据库中。在这些步骤之后,作者steven sanderson建议我们需要更新实体框架概念模型,以便db和我的域对象正确地映射在一起。更新实体框架概念模型
我没有在我的解决方案中使用sportsstore.edmx文件,因为我们开始使用本书的POCO对象和源代码也缺少edmx文件?
由于我通过编辑产品获取此错误上传图像?
不允许将数据类型nvarchar(max)隐式转换为varbinary。使用CONVERT函数来运行此查询。
描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。
异常详细信息:System.Data.SqlClient.SqlException:不允许将数据类型nvarchar(max)隐式转换为varbinary。使用CONVERT函数来运行此查询。
为我的产品类中定义:
public class Product
{
[HiddenInput(DisplayValue = false)]
public int ProductID { get; set; }
[Required(ErrorMessage="Please enter a Product Name")]
public string Name { get; set; }
[Required(ErrorMessage="Please enter product description")]
[DataType(DataType.MultilineText)]
public string Description { get; set; }
[Required(ErrorMessage="Please enter product price")]
[Range(0.01, double.MaxValue,ErrorMessage="Please enter positive price")]
public decimal Price { get; set; }
[Required(ErrorMessage="Please enter product category")]
public string Category { get; set; }
public byte[] ImageData { get; set; }
[HiddenInput(DisplayValue = false)]
public string ImageMimeType { get; set; }
}
我的产品表定义为
您将ImageMimeType声明为代码中的字符串,但它在数据库中声明为二进制字段。 – Oxymoron