//---------------保存CRMAnnouce--------------------------- public CRMAnnouce Save(CRMAnnouce entity) { if (this.dataCtx.Connection != null) { if (this.dataCtx.Connection.State == ConnectionState.Closed) { this.dataCtx.Connection.Open(); } } DbTransaction tran = this.dataCtx.Connection.BeginTransaction(); dataCtx.Transaction = tran; try { var qry = from t in CRMAnnouces where t.ID == entity.ID select t; var obj = qry.SingleOrDefault(); if (obj != null) { this.CopyEntity(obj, entity); } else { this.CRMAnnouces.InsertOnSubmit(entity); } this.dataCtx.SubmitChanges(); tran.Commit(); return(entity); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { dataCtx.Connection.Close(); } }
//---------------保存CRMAnnouce--------------------------- public CRMAnnouce Save(CRMAnnouce entity) { if (this.dataCtx.Connection != null) if (this.dataCtx.Connection.State == ConnectionState.Closed) this.dataCtx.Connection.Open(); DbTransaction tran = this.dataCtx.Connection.BeginTransaction(); dataCtx.Transaction = tran; try { var qry = from t in CRMAnnouces where t.ID == entity.ID select t; var obj = qry.SingleOrDefault(); if (obj != null) this.CopyEntity(obj, entity); else this.CRMAnnouces.InsertOnSubmit(entity); this.dataCtx.SubmitChanges(); tran.Commit(); return entity; } catch (Exception ex) { tran.Rollback(); throw ex; } finally { dataCtx.Connection.Close(); } }