Reputation: 77
The SQL query that I wrote to retreive the data I wanted.
Select JobQuestionType
From JobQuestionTypes AS J
INNER JOIN JobQuestions AS JQ ON J.JobQuestionTypeId = JQ.QuestionType
Where JobId = 3813 AND Active = 1
Order By JobQuestionId ASC
For the above SQL query I wrote the LINQ query using c# as below.
var questionTypes = _context.JobQuestionTypes.Join(_context.JobQuestions,
jobQuestionTypes => jobQuestionTypes.JobQuestionTypeId,
jobQuestions => jobQuestions.JobQuestionType,
(jobQuestionTypes, recruiters) => new { jobQuestionTypes, recruiters })
.Where(item => item.JobId.Equals(JobId) && !item.jobQuestionTypes.Active)
.Select(item => item.jobQuestionTypes.JobQuestionType).OrderBy(x => x.JobQuestionId).ToList();
I am getting an error
The type arguments for method 'Queryable.Join<TOuter, TInner, TKey, TResult>(IQueryable, IEnumerable, Expression<Func<TOuter, TKey>>, Expression<Func<TInner, TKey>>, Expression<Func<TOuter, TInner, TResult>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
How can I solve it. I am new to c#.
(Iam getting the expected output from my sql query. I want to convert it into linq)
Thankyou.
Upvotes: 0
Views: 180
Reputation: 41
var result= (from j in _context.JobQuestionTypes
join JQ in _context.JobQuestions on j.JobQuestionTypeId equals JQ.QuestionType
where j.JobId = 3813 AND j.Active = 1
orderby j.JobQuestionId
select j.JobQuestionType).FirstOrDefault();
Upvotes: 0