TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Madhav Sharma
889
899
39.3k
Getting error "Lambda expression used inside Include is not"
May 30 2020 11:34 AM
Once I writting quary
var testresult = await _unit.Context.Tbltest.Include(p => p.Tblquestion).
ThenInclude(post => post.Tblquestionoptions.Where(k => k.Id == id)).Where(t => t.Id == id).FirstOrDefaultAsync();
It
throw
exception
"Lambda expression used inside Include is not"
Full Code :
public
async Task<ApiResult<TestQueryModel>> GetQuestionOptionByIdAsync(
long
id)
{
TestQueryModel modeltest =
null
;
try
{
//var testresult = await _unit.Context.Tbltest.Include(blog => blog.Tblquestion)
//.ThenInclude(post => post.Tblquestionoptions).Where(t => t.Id == testId).FirstOrDefaultAsync();
//var testresult1 = await _unit.Context.Tblquestion.Include(post => post.Tblquestionoptions).
// Where(t => t.Id == id).FirstOrDefaultAsync();
var testresult = await _unit.Context.Tbltest.Include(p => p.Tblquestion).
ThenInclude(post => post.Tblquestionoptions.Where(k => k.Id == id)).Where(t => t.Id == id).FirstOrDefaultAsync();
if
(testresult !=
null
)
{
modeltest =
new
TestQueryModel();
modeltest.UserId = CurrentUserInfo.CurrentUser;
modeltest.TestId = testresult.Id;
modeltest.GradeId = testresult.GradeId;
modeltest.SubjectId = testresult.SubjectId;
modeltest.TopicId = testresult.TopicId;
modeltest.Questions = testresult.Tblquestion.Select(q =>
new
TestQuestionQueryModel
{
Question = q.Name,
QuestionId = q.Id,
Options = q.Tblquestionoptions.Select(t =>
new
TestQuestionOptionsQueryModel
{
OptionId = t.Id,
Option = t.Name,
IsSelect = t.IsMatched.HasValue ? t.IsMatched.Value :
false
}).ToList()
}).ToList();
return
new
ApiResult<TestQueryModel>(
new
ApiResultCode(ApiResultType.Success), modeltest);
}
return
new
ApiResult<TestQueryModel>(
new
ApiResultCode(ApiResultType.Error, messageText:
"no data found"
));
}
catch
(Exception ex)
{
ErrorTrace.Logger(LogArea.RepositoryLayer, ex);
return
new
ApiResult<TestQueryModel>(
new
ApiResultCode(ApiResultType.Error, messageText:
"Error while geting data"
));
}
}
Reply
Answers (
2
)
Printing POS Receipt Online
ASP.NET Core Razor - Post input, variable and string values