现在,我有一个包含学生 ID 和学生姓名的数据库。
studentsCollection.Where(c => c.ID.Contains(":"));
然后,我只想带那些ID中有“冒号”的学生。而且,当我只使用 where 子句时,我会收到类似“edititem is not allowed for this view”之类的错误。但是,当我把句子变成(下)
studentsCollection.Where(c => c.ID.Contains(":")).ToList();
添加 ToList 函数;它将能够编辑但不能更新甚至删除。
有谁知道我可以如何修改这个错误?
如果没有足够的信息知道我在问什么,请告诉我,谢谢。
-----编辑-----
下面是我的已选择更改功能。
错误情况:当我只使用 where 子句时,我会得到“edititem is not allowed for this view” 无法 更新情况:当我添加 ToList 函数时,我会工作;但是,我不会更新我的数据。
private void StudentsDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedStudents = e.AddedItems[0] as Students;
var studentsCollection = selectedStudents.Data;
studentsCollection.AssociationChanged += ColumnsCollection_Changed;
var studentsViewSource = ((CollectionViewSource)(this.FindResource("StudentsDataViewSource")));
studentsViewSource.Source = studentsCollection.Where(c => c.ID.Contains(":")).ToList();
}
private void ColumnsCollection_Changed(object sender, System.ComponentModel.CollectionChangeEventArgs e)
{
if (e.Action == CollectionChangeAction.Remove)
{
studySystemEntities.Data.DeleteObject(e.Element as Data);
}
else if (e.Action == CollectionChangeAction.Add)
{
studySystemEntities.Data.AddObject(e.Element as Data);
}
}