我正在尝试调试以下代码行
binding.DataSource = this.bindingSource.DataSource;
并希望了解有关binding.DataSource
的更多信息在即时窗口查询? binding.DataSource返回
Count = 1
[0]: {Contact Events}
我想将binding.DataSource转换为我可以使用intellisense查询的内容吗? 我该怎么把它投到?
[更新] 绑定源创建如下;
public BindingSource GetEventTypesBindingSource()
{
try
{
DbSet<ContactEventType> dset = base.Context.ContactEventTypes;
IOrderedQueryable<ContactEventType> qry = dset.Where(p => p.Id > 0).OrderBy(x => x.Description);
qry.Load();
var bindingSource = new BindingSource();
bindingSource.DataSource = dset.Local.ToBindingList();
return bindingSource;
}
catch (Exception ex)
{
HandleException.Show(ex);
}
return null;
}
[更新] 我在调试器中尝试了以下内容
? (List<ContactEvent>) binding.DataSource.GetType()
但是
The type or namespace name 'List' is not valid in this scope
答案 0 :(得分:1)
可能是List<ContactEvent>
,但您可以找到使用调试器和/或反射。
如果在调试器的Watch窗口中查看变量,它将显示数据的类型。如果在数据源上调用GetType,它将返回对象的类型(您也可以在调试器中执行此操作,并在那里检查结果类型)。
答案 1 :(得分:1)
首先它与答案无关,但在这种情况下你不必使用数据源(你不使用datamember属性)。你可以直接将它绑定到集合。 集合的类型可以是来自实体框架程序集的自定义绑定列表实现。也许你没有看到它的名字,因为它不公开,但铸造到IEnumerable应该工作。 如果我没记错的话,自定义实现派生自BindingList,那么BindingList也可以。