I have a table in my database and one of its columns is in Image data type. I can store Image in database but I can’t retrieve it. I want to retrive Image for each logged in user. I used this code:
public ActionResult ShowImage()
{
var userID = GetUserID();
var advert = from ad in StoreDb.Ads where ad.UserId == userID select ad.AdImage;
return File(advert, "Image");
}
But got this error:
Error 2 Argument 1: cannot convert from ‘System.Linq.IQueryable’ to ‘string’ C:\Users\Tena\Documents\Visual Studio 2010\Projects\MvcApplication6\MvcApplication6\Controllers\Default3Controller.cs 92 25 MvcApplication6
The problem is that advert is in
System.Linq.IQueryable<>byte[]
format but File needs byte[] format. What should I do now? Any answer is helpful.
Thanks
The problem is that the LINQ query isn’t being evaluated and the query as it stands could theoretically return more than one result (hence it’s an
IQueryable).In fact the query doesn’t look right as presumably there will be more than one advert for a particular user and I wouldn’t expect the adverts to be stored according to user in any case, but I don’t know anything about your data structure, so I’ll just try to help you make the query work and you can refine it later.
Try changing this line:
to this:
I could give you other tips around how to do this, but try that first and see what happens.