在Linq to SQL asp.net中,我想从数据库中提取特定图像并显示在aspx页面上。我在代码中声明返回类型为“var”。所以在获取图像之后,它将图像分配给var类型。如何将类型'system.linq.iqueryable <byte[]>'转换为'byte []'
下面是代码:
var db = from c in context.Images
where c.imageId == iID
select c.imageData;
return new MemoryStream((byte[])db); ---->> this line of code gives error
它给出了这样的编译错误:无法转换类型 'system.linq.iqueryable' 到 '字节[]'。
如何将'system.linq.iqueryable类型转换为byte []?
你应该使用LINQ中的SingleOrDefault选择,这样你就可以得到的只是一个单一的对象,不是IQueryable。同样在SingleOrDefault <>中,您可以指定类型以避免铸造 – Carlos487