using (var transaction = context.Database.BeginTransaction()){try{ FAContract fa = GetFAContract();context.Entry(fa).State = EntityState.Deleted;var query = (from fad in context.FAContractDetail where fad.FACID == fa.ID select fad);foreach (var i in query){context.Entry(i).State = EntityState.Deleted;var Queryinvoice = (from qi in context.FAContractInvoice where qi.FAContractDetailID == i.ID select qi);foreach (var ii in Queryinvoice){context.Entry(ii).State = EntityState.Deleted;}var QueryPrePay = (from qpp in context.FAContractPrePayment where qpp.FAContractDetailID == i.ID select qpp);foreach (var ipp in QueryPrePay){context.Entry(ipp).State = EntityState.Deleted;}var QueryPre = (from qp in context.FAPayment where qp.FAContractDetailID == i.ID select qp);foreach (var ip in QueryPre){context.Entry(ip).State = EntityState.Deleted;}}int c = context.SaveChanges();transaction.Commit();if (c > 0) {MessageBox.Show("删除完成!", "提示");} }catch (Exception ex){transaction.Rollback();Console.WriteLine("事务处理失败");}}