现有这样的需求:
我在数据库中保存图片的形式是二进制的,我想在数据库初始化的时候插入几条数据,代码如下:(standard后面是二进制数据),
List<Picture> pic = new List<Picture> { new Picture("Standard", ,true,"GuidePic",false,1,"2013-09-24","2013-10-10",null,"2013-09-24"), new Picture("Standard", ,true,"GuidePic",false,2,"2013-09-24","2013-10-10",null,"2013-09-24"), new Picture("Standard", ,true,"GuidePic",false,3,"2013-09-24","2013-10-10",null,"2013-09-24") , new Picture("Standard", ,true,"GuidePic",false,4,"2013-09-24","2013-10-10",null,"2013-09-24") };
我在二进制数据字段试了null,编译的时候报错,网上也没有这方面的资料,在此求教各位大神,给小弟一个解决办法,小弟在此谢过了。。
试试http://www.cnblogs.com/humble/p/3320804.html
数据库中存储图片的字段是否允许为null
图片可以为空,但是在数据库初始化的时候提示不能用null
是我的模型里面没有构造函数。。
对应的实体属性是如何定义的?
实体里面没有定义构造函数,所以用上面那个方法编译的时候出错了,换成这样就行了,代码如下:
new Picture{ SchoolCode="Standard", PicPath="/Files/Mobile/Pic/xiadaloading.png",IsDisplay=true, PicType="WelPic", IsDelete=false, Order=1, StartTime=Convert.ToDateTime("2013-09-24"),EndTime=Convert.ToDateTime("2013-10-10"), CreateTime=Convert.ToDateTime("2013-09-23") },
new Picture{ SchoolCode="Standard", PicPath="/Files/Mobile/Pic/5.jpg",IsDisplay=true, PicType="GuidePic", IsDelete=false, Order=2, StartTime=Convert.ToDateTime("2013-09-24"),EndTime=Convert.ToDateTime("2013-10-10"), CreateTime=Convert.ToDateTime("2013-09-23") },
new Picture{ SchoolCode="Standard", PicPath="/Files/Mobile/Pic/8.jpg",IsDisplay=true, PicType="GuidePic", IsDelete=false, Order=3, StartTime=Convert.ToDateTime("2013-09-24"),EndTime=Convert.ToDateTime("2013-10-10"), CreateTime=Convert.ToDateTime("2013-09-23") },
new Picture{ SchoolCode="Standard", PicPath="/Files/Mobile/Pic/9.jpg",IsDisplay=true, PicType="GuidePic", IsDelete=false, Order=4, StartTime=Convert.ToDateTime("2013-09-24"),EndTime=Convert.ToDateTime("2013-10-10"),CreateTime=Convert.ToDateTime("2013-09-23")}
谢谢各位大神给我建议,谢谢了