简体   繁体   English

实体框架4包含+表连接无法一起使用

[英]Entity Framework 4 Include + Table joining does not work together

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... 结果的Photo和HomeTelephone属性为空,但设置了PhotoId和HomeTelephone ...

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM