我有下面的代碼,出現以下錯誤:ASP.NET轉換的IQueryable列出
Error 1 Cannot implicitly convert type
'System.Linq.IQueryable<Receptura_v4.Models.ReceptDTO>'
to'Receptura_v4.Models.ReceptDTO'
. An explicit conversion exists (are you missing a cast?)
任何想法如何解決呢?
public ReceptDTO GetReceptForUser(string userId)
{
using (ApplicationDbContext db = new ApplicationDbContext())
{
var q = from r in db.Recipes where r.UserId == userId select new ReceptDTO
{
RecipeID = r.RecipeID,
Title = r.Title,
Portion = r.Portion,
Time = r.Time,
Category = r.Category,
Preparation = r.Preparation,
Difficulty = r.Difficulty,
Views = 0,
Price = r.Price,
Date = DateTime.Now,
UserId = userId
};
return q;
}
}