このエラーが発生しています。「エンティティまたは複合型 'MvcApp.Models.Survey' は、LINQ to Entities クエリで構築できません。」
これは私のクエリです:
var surveys3 = (from s in db.Surveys
where s.AccountId == appAcc.Id
select new Survey
{
Id = s.Id,
Title = s.Title,
Description = s.Description,
NumberOfQuestions = (from q in s.Questions
select q).Count()
}).ToList();
View(surveys3);
.ToList() を .AsEnumerable() に変更しようとしましたが、foreach でモデルをループしようとすると View(surveys3) が失敗します
私のモデルクラスは次のようになります。
public class Survey
{
[Required]
[Key]
public long Id { get; set; }
[Required]
[StringLength(100)]
public string Title { get; set; }
[DataType(DataType.MultilineText)]
public string Description { get; set; }
[DataType(DataType.DateTime)]
public DateTime CreatedOn { get; set; }
[NotMapped]
public Int32 NumberOfQuestions { get; set; }
public virtual ICollection<Question> Questions { get; set; }
[ForeignKey("AccountId")]
public ApplicationAccount Account { get; set; }
[Required]
public long AccountId { get; set; }
}