为什么实体框架会抛出此错误? [英] Why is entity framework throwing this error?
本文介绍了为什么实体框架会抛出此错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ex.Message = "Unable to update the EntitySet 'ExternalEmployees' because it has a DefiningQuery and no <UpdateFunction> element exists in the <ModificationFunctionMapping> element to support the current operation."
if(externalEmployeeDataGrid.IsVisible)
{
ExternalEmployee selectedEmployee = (ExternalEmployee)externalEmployeeDataGrid.SelectedItem;
ExternalEmployee ExtEmpContext = this.context.ExternalEmployees.Find(selectedEmployee.ID);
if(ExtEmpContext != null)
{
ExtEmpContext.BadgeNo = selectedEmployee.BadgeNo;
ExtEmpContext.EmployeeName = selectedEmployee.EmployeeName;
ExtEmpContext.EmployeeType = selectedEmployee.EmployeeType;
// ExtEmpContext.Status = selectedEmployee.Status;
context.SaveChanges();
}
}
这是实体设置......
Here is Entity setup...
public ExternalEmployee newExternalEmployee { get; set; }
NewMealPlanEntities context = new NewMealPlanEntities();
CollectionViewSource externalEmployeesViewSource;
public ExternalEmployeesWindow()
{
InitializeComponent();
externalEmployeesViewSource = ((CollectionViewSource)FindResource("externalEmployeeViewSource"));
DataContext = this;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//System.Windows.Data.CollectionViewSource externalEmployeeViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("externalEmployeeViewSource")));
// Load data by setting the CollectionViewSource.Source property:
// externalEmployeeViewSource.Source = [generic data source]
context.ExternalEmployees.Load();
externalEmployeesViewSource.Source = context.ExternalEmployees.Local;
我的尝试:
我确实注意到一个错误,在早期,表明该表没有主键,但我更正了,删除了edmx,并重新生成了所有内容。
有趣的东西! :(
What I have tried:
I did notice an error, early on, indicating that the table does not have a primary key but I corrected that, deleted the edmx, and re-generated everything.
fun stuffs! :(
推荐答案
好的,
神圣粗心,蝙蝠侠!
我最初指向服务器连接到同一个表名所在的位置没有主键,所以实体是用只读表创建的。
幸运的是,我能够在指向正确的服务器后放弃EDMX并重新生成它。
OK,
Holy carelessness, Batman!
I had originally pointed server connection to where the same table name was located that did NOT have a primary key so entity was created with read-only table.
Fortunately, I was able to drop the EDMX and re-generate it after pointing to the correct server.
这篇关于为什么实体框架会抛出此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文