I have two tables "Users" and "UserType". There is a relationship between these tables on "userTypeID" column. This column is primary key in the "UserType" table and foreign key in the "User" table. I also have a property in "User" class like follows:
public virtual UserType usertype{ get; set; }
I am querying "User" table like follows:
List<MyApp.Entity.Models.User> userList = new List<User>();
using (var DBContext = new UserDBContext())
{
userList = DBContext.User.Where(x => x.IsActive == true).OrderBy(i => i.userName).ToList();
return userList;
}
When I am debugging the code, userList.usertype is null. I need to have the UserType in the userList. What am I doing wrong? I am new to Entity Framework.
userList.You context returns that list.