错误提示:“An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.” 1.首先我是在UI层把PurchaseOrder读取,然后做了修改。 2. 然后还是在UI层,把PurchaseOrderDetails也做了修改,这个修改有可能是ADD,EDIT,DELETE,然后再用purchaseOrder.PurchaseOrderDetails.Add(p);的方法把从表附加到主表中的。 3. 然后提交。 4. 处理数据:我已经在purchaseorderdetail表中加了一个Version的timestamp字段 private bool update(PurchaseOrder po) { DataContext context = new DataContext(ConnString()); context.GetTable<PurchaseOrder>().Attach(po, true); context.SubmitChanges(); 会提示:“An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.”
如果把上面context.GetTable<PurchaseOrder>().Attach(po, true); 换成 PurchaseOrder purchaseOrder; purchaseOrde = context.PurchaseOrder.Single(p => p.PurchaseOrderID == po.PurchaseOrderID); context.PurchaseOrders.Attach(po, purchaseOrder);如果换成这样写的话会提示An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported. 还有主键已经存在什么的,种种错误,我找了好多种方法,都不行