I am trying to display multiple username with their image So, I have a Json action method like this:
public JsonResult GetUsers()
{
var ret = (from user in db.Users
orderby user.UserName
select new
{
UserName = user.UserName,
Pic = GetFileData(user.Id),
}).AsEnumerable();
return Json(ret, JsonRequestBehavior.AllowGet);
}
And this is my GetFileData
method to get user's image:
public FileResult GetFileData(int Id)
{
var avatarImage = db.Files.SingleOrDefault(s => s.ApplicationUserId == Id);
return File(avatarImage.Content, avatarImage.ContentType);
}
Here, ApplicationUserId
is the foreign key relating File and ApplicationUser
class.
Now, when I run the query, I should get username with their pic But I am getting System.NotSupportedException
.The complete error message is:
LINQ to Entities does not recognize the method
'System.Web.Mvc.FileResult GetFileData(Int32)' method, and this method
cannot be translated into a store expression.
How to get it resolved.I have seen many stackoverflow question relating it but none of the question was relating to FileResult.The code for view page is here http://pastebin.com/AyrpGgEm
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…