ProductDataContext pdc = new ProductDataContext(CONNECTSTRING); Product product = pdc.Proudct.Single(p => p.ProductId == 444); pdc.Attach(product);//附加实体---增加此段代码即可解决“无法删除尚未附加的实体”问题 pdc.Product.DeleteProduct(product);//删除数据 pdc.SubmitChanages();
ProductDataContext pdc = new ProductDataContext(CONNECTSTRING); Product product = pdc.Proudct.Single(p => p.ProductId == 444); pdc.Attach(product);//附加实体---增加此段代码即可解决“无法删除尚未附加的实体”问题 pdc.Product.DeleteProduct(product);//删除数据 pdc.SubmitChanages();