I couldn’t find an answer to this. I’m sure the answer is simple, I don’t think I was searching for the right thing.
I have a .dbml file with two tables: Employees and Departments. There’s a relationship between the two, Employees has a DepartmentID.
Anyways, I’m doing this in my code:
Employee emp = Employee.Get(123);
string fname = emp.FirstName;
string lname = emp.LastName;
string deptName = emp.Department.Name;
string deptCode = emp.Department.Code;
What I’m wondering is, every time I call emp.Department, is that making a database call? Or was all that information loaded when I created the Employee object?
It made a trip to database, when you first accessed
emp.Department.Nameunless deferred loading is turned off.It won’t make another trip when you say
emp.Department.Codein next statement, it would have already got theDeparmentobject in memory.This answer explains it in more detail.
You may want to see