I have the following Model class:
public partial class EmployeeInfo
{
public int EmployeeInfoId { get; set; }
public string FirstName { get; set; } = null!;
public int? JobTitleLookupId { get; set; }
public virtual JobTitleLookup? JobTitleLookup { get; set; }
}
public partial class JobTitleLookup
{
public int JobTitleLookupId { get; set; }
public string Title { get; set; } = null!;
public virtual ICollection<EmployeeInfo> EmployeeInfos { get; } = new List<EmployeeInfo>();
}
I have JobTitleLookupId
in my employeeeInfo
database table. How can i get the name of the jobtitle if i have the corresponding ID in employeeInfo Table.
below is my JobTitleLookup table:
JobTitleLookupID title
1 title1
2 title2
3 title3
EmployeeInfo table
EmployeeInfoId FirstName JobTitleLookupID
1 test1 2
2 test3 1
3 testx 3
How can I get the job title if I have the employeeinfoId and jobTitleLookupID using LINQ.'
this is what I tried so far:
public async Task<List<string?> GetJobTitle(string employeeId)
{
var query = _ackContext.EmployeeInfos
.Include(c => c.JobTitleLookup)
.Where(c => c.EmployeeNumber == employeeId)
}
this is something I wrote in sql. I want the same in LINQ
SELECT
title
FROM
employeeInfo e
INNER JOIN JobTitleLookup j ON
e.JobTitleLookupID =j.JobTitleLookupID
AND
EmployeeInfoID = 212;