This is caused because of Where-Expression.
You should only use variables in there or call methods that can be translated to SQL.

First, save your Session value in a variable:

int userId= (int)Session["UserId"];
posts = db.Posts.Where(a => a.UserId == userId)

Then use userId in your Where-Expression.