gpt4 book ai didi

c# - Entity Framework 4 Include + Table joining 不能一起工作

转载 作者:行者123 更新时间:2023-11-30 12:35:40 26 4
gpt4 key购买 nike

我想选择加载了照片和电话实体的员工。我正在使用这样的查询:

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

结果的 Photo 和 HomeTelephone 属性为空值,但设置了 PhotoId 和 HomeTelephone...

我做错了什么?

最佳答案

也许这可以解决您的问题。

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

关于c# - Entity Framework 4 Include + Table joining 不能一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5030219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com