public virtual PollSection InsertPollSection(PollSection entity) { PollSection other = new PollSection(); other = entity; if (entity.IsTransient()) { string sql = @"Insert into PollSection ( [PollID] ,[SectionID] ,[CreatedOn] ) Values ( @PollID , @SectionID , @CreatedOn ); Select scope_identity()" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@PollID", entity.PollId) , new SqlParameter("@SectionID", entity.SectionId) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; var identity = SqlHelper.ExecuteScalar(this.ConnectionString, CommandType.Text, sql, parameterArray); if (identity == DBNull.Value) { throw new DataException("Identity column was null as a result of the insert operation."); } return(GetPollSection(Convert.ToInt32(identity))); } return(entity); }
public virtual PollSection UpdatePollSection(PollSection entity) { if (entity.IsTransient()) { return(entity); } PollSection other = GetPollSection(entity.PollId); if (entity.Equals(other)) { return(entity); } string sql = @"Update PollSection set [SectionID]=@SectionID , [CreatedOn]=@CreatedOn where PollID=@PollID" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@PollID", entity.PollId) , new SqlParameter("@SectionID", entity.SectionId) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray); return(GetPollSection(entity.PollId)); }