为什么这不起作用?:
var surveys = db.Surveys.Where(s => s.Author.UserId == user.UserId);
return from survey in surveys
select new
{
surveyId = survey.SurveyId,
title = survey.Title
};
而这个,稍作改动,是?:
var surveys = db.Surveys.Where(s => s.Author == user);
return from survey in surveys
select new
{
surveyId = survey.SurveyId,
title = survey.Title
};
它会引发序列化错误
The 'ObjectContent`1' type failed to serialize the response body for content type
'application/xml; charset=utf-8'. (...)
我可以用这种方式解决它,但我在这里(如下)有同样的错误,并且不能用同样的方式解决它:
var surveys = db.Surveys.Where(s => s.AnswerableBy(user));