Entity Framework 4 Include + Table join does not work together

I want to select an employee with uploaded photographic and telephone objects. I use a query like this:

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 is null for the Photo and HomeTelephone properties, but has PhotoId and HomeTelephone ...

What am I doing wrong?

+4
source share
1 answer

Perhaps 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(); 
+2
source

Source: https://habr.com/ru/post/1340182/


All Articles