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
> 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
( new ApiResultCode(ApiResultType.Success), modeltest); - }
- return new ApiResult
( new ApiResultCode(ApiResultType.Error, messageText: "no data found")); - }
- catch (Exception ex)
- {
- ErrorTrace.Logger(LogArea.RepositoryLayer, ex);
- return new ApiResult
( new ApiResultCode(ApiResultType.Error, messageText: "Error while geting data")); - }
- }

Madhav SharmaPosted May 30, 2020, 11:58 AM
Salman BegPosted May 30, 2020, 11:52 AM