如何使用 .Include 方法从数据库中获取多个相关属性(不同类型)?
How do I use the .Include method to get multiple related properties (of different types) from database?
我想从我的数据库中名为 'Appointments' 的 Table 获取信息,并获取与每个约会相关的所有 'Treatments' 和 'Users'。
我尝试使用 System.Data.Entity
中的 .Include
,但只能让它带来一个相关的 属性,因为我需要它们。
using System.Data.Entity;
public override List<Appointment> GetAll()
{
using (DB = new DBModel())
{ return DB.Appointments.Include(a => a.Treatments).ToList(); }
}
有没有一种方法可以使用 include 带来超过 1 个相关 属性?
如果没有,我怎样才能带来超过 1 个相关的 属性 呢?
您应该能够像这样链接包含内容
return DB.Appointments
.Include(a => a.Treatments)
.Include(a => a.Users)
.ToList();
我想从我的数据库中名为 'Appointments' 的 Table 获取信息,并获取与每个约会相关的所有 'Treatments' 和 'Users'。
我尝试使用 System.Data.Entity
中的 .Include
,但只能让它带来一个相关的 属性,因为我需要它们。
using System.Data.Entity;
public override List<Appointment> GetAll()
{
using (DB = new DBModel())
{ return DB.Appointments.Include(a => a.Treatments).ToList(); }
}
有没有一种方法可以使用 include 带来超过 1 个相关 属性? 如果没有,我怎样才能带来超过 1 个相关的 属性 呢?
您应该能够像这样链接包含内容
return DB.Appointments
.Include(a => a.Treatments)
.Include(a => a.Users)
.ToList();