I'm looking for the equivalent LINQ Lambda expression for this SQL statement.
SELECT A.USER_ID, A.GIVEN_NAME, A.SURNAME, A.REGION, A.EMAIL
FROM USER A
WHERE A.USER_ID IN (
SELECT B.USER_ID_TXT
FROM TRAINING_COURSE B
WHERE B.COURSE_ID_TXT IN
(SELECT C.MITT_COURSE_ID_TXT
FROM TRAINING_MITT C
WHERE C.TRAINING_ID =
(SELECT D.TRAINING_ID
FROM TRAINING_ROLE D
WHERE D.ROLE_ID = 3011)))
Here are the entities. I've added some comments to illustrate the reference to the TABLES and FIELDS in the SQL query.
This table store users information and it is mounted as a Materialized view.
// TABLE USER
public class TCUser
{
// Field USER_ID
public string UserId { get; set; }
public string GivenName { get; set; }
public string Surname { get; set; }
public string OfficeBuilding { get; set; }
public string Address { get; set; }
public string FloorLocation { get; set; }
public string FloorNumber { get; set; }
public string Region { get; set; }
public string Province { get; set; }
public string PostalCode { get; set; }
public string City { get; set; }
public string Email { get; set; }
}
The next table store training course and it comes from an external source. It is basically an import of the data.
// TABLE TRAINING_COURSE - EXTERNAL SOURCE
public class TrainingCourse
{
// Field USER_ID_TXT
public String UserId { get; set; }
// Field COURSE_ID_TXT
public String CourseId { get; set; }
public String CourseDescription { get; set; }
public String ScheduleId { get; set; }
public String ScheduleDescription { get; set; }
public DateTime? ScheduleStartDate { get; set; }
public DateTime? ScheduleEndDate { get; set; }
public String Status { get; set; }
}
This table make association of training courses required to fulfill a role.
// TABLE TRAINING_ROLES - XREF between TRAINING_MITT and ICS_ROLE
public class IcsTrainingRole
{
// Field ROLE_ID
public int RoleId { get; set; }
// Field TRAINING_ID
public int TrainingId { get; set; }
public virtual IcsTraining IcsTraining { get; set; }
public virtual IcsRole IcsRole { get; set; }
}
This table do the association of Training with the external MITT Training DB
// TABLE TRAINING_MITT
public class IcsTrainingMitt
{
// Field TRAINING_ID
public int TrainingId { get; set; }
// Field MITT_COURSE_ID_TXT
public string MittCourseId { get; set; }
public virtual IcsTraining IcsTraining { get; set; }
}
public class IcsTraining
{
public int TrainingId { get; set; }
public string TrainingName { get; set; }
public virtual ICollection<IcsTrainingRole> IcsTrainingRoles { get; set; }
public virtual ICollection<IcsTrainingMitt> IcsTrainingMitt { get; set; }
}
public class IcsRole
{
public int RoleId { get; set; }
public int SectionId { get; set; }
public string RoleName { set; get; }
public virtual ICollection<IcsTrainingRole> IcsTrainingRoles { get; set; }
}