现在,我根据实体模型的对象上下文创建了一个新的对象数据源。然后,我创建了一个 BindingSource 和一个设置为此 BindingSource 的 DataGridView。
我可以添加绑定到 TraceLine 表中的数据的列。当我设置 DataSource 时,我会在这些列中看到值。但是,我似乎无法从连接表中获取数据。如何将 DataGridView 绑定到具有联接的查询?
using (var entities = new MyEntities())
{
var lines = from t in entities.Lines
join m in entities.Methods on t.MethodHash equals m.MethodHash
where t.UserSessionProcessId == m_SessionId
select new
{
m.Name, // doesn't get displayed in DataGridView, but I want it to
t.Sequence,
t.InclusiveDuration,
t.ExclusiveDuration
};
dgvBindingSource.DataSource = lines;
}