我在将RadTreeView
元素绑定到数据源时遇到问题,实际上在设置ValueMember
时。简化,有:
型号:
/// Parent
public class EmfLocation
{
public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<EmfDataSet> EmfDataSets { get; set; }
}
/// Child
public class EmfDataSet
{
public int ID { get; set; }
public string Name { get; set; }
public int EmfLocationID { get; set; }
}
查看:
/// treeDataset = new Telerik.WinControls.UI.RadTreeView();
private void GetTreeData()
{
IList<EmfLocation> locationList = new List<EmfLocation>();
locationList = repoEmfLocation.GetBy(testingId).ToList();
treeDataset.DataSource = locationList;
treeDataset.DisplayMember = "Name\\Name";
treeDataset.ChildMember = "locationList\\EmfDataSets";
treeDataset.ValueMember = "ID\\ID";
}
一切正常,根节点的值成员设置正常,但对于子节点(EmfDataSet)
而不是值,有一个"TargetInvocationException"
:
"Property accessor 'ID' on object 'System.Data.Entity.DynamicProxies.EmfDataSet_5F54359CCE6567583EDAE4FA2B61B7D274184C3985DAC9FE14B234AFFEE42F1B' threw the following exception:'Object does not match target type.'"
有什么问题?