我有一个用于项目(父)和角色分配(子)的父子设置。关联的表和关系已在 中设置,dataset
我正在使用 a 读取和修改内容(这似乎是wpfBindingListCollection
中最接近 a 的东西)。BindingSource
然而,问题是我无法同时添加父行和子行。如果我创建父行并提交到数据库,然后添加子行,它就可以工作。有没有办法同时添加父行和子行。
添加子行的代码:
if (projectRoleAllocationView.CanAddNew)
{
System.Data.DataRowView roleItem = (System.Data.DataRowView)availableRoleViewSource.View.CurrentItem;
System.Data.DataRowView roleAllocationItem = (System.Data.DataRowView)roleAllocationViewSource.View.CurrentItem;
System.Data.DataRowView projectItem = (System.Data.DataRowView)projectView.CurrentItem;
System.Data.DataRowView projectRoleAllocationItem = (System.Data.DataRowView)projectRoleAllocationView.AddNew();
projectRoleAllocationItem.Row["ID"] = Guid.NewGuid();
projectRoleAllocationItem.Row["ProjectID"] = projectItem.Row["ID"];
projectRoleAllocationItem.Row["RoleAllocationID"] = roleAllocationItem.Row["ID"];
projectRoleAllocationItem.Row["RoleName"] = roleItem.Row["Name"];
projectRoleAllocationItem.Row["ResourceName"] = roleAllocationItem.Row["Name"];
projectRoleAllocationView.CommitNew();
projectRoleAllocationView.Refresh();
}