I want to select the employee with loaded photo and telephone entities. I am using such query:
var empl = from user in ObjectContext.Users
from employee in ObjectContext.Employees.Include("Photo").Include("HomeTelephone")
where
user.Id == userId &&
employee.Id == user.EmployeeId &&
employee.Deleted == false &&
employee.OwnerOrganizationId == Singleton.OrganizationId
select employee;
var result = empl.FirstOrDefault();
the result have nulls for Photo and HomeTelephone properties, but has PhotoId and HomeTelephone set...
What I am doing wrong?
Maybe this solves your problem.
User user;
using (var ctx = new Model1Container())
{
user = ctx.UserSet
.Include("Employee")
.Include("Employee.Photo")
.Include("Employee.Telefon")
.Single(x => x.Id == id);
}
Console.Out.WriteLine(user.UserName);
Console.Out.WriteLine(user.Employee.Telefon.First().Number);
Console.ReadLine();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.