I want to join tables using linq, based on the definition of the model. Example of what I want:
from department in User.departments...
My classes are:
USER CLASS:
public class User
{
public User() {
Departments = new List<Department>();
}
public int UserId { get; set; }
public string UserName { get; set; }
public virtual ICollection<Department> Departments { get; set; }
}
DEPARTMENT CLASS:
public class Department
{
public int DepartmentId { get; set; }
public string DepartmentName { get; set; }
public virtual User User { get; set; }
}
I'm creating inside the user class this:
public bool hasDepartment(int DepartmentId, int UserId)
{
var test = from department in User.departments
//...
}
But I'm having this message: 'User' does not contain a definition for 'departments'.
I'm creating a ASP.NET MVC application. Am I doing anything wrong?