public int Update <T>(RepositoryRecord <T> item, string userName) where T : RepositoryRecord <T>, new() { if (userName == null) { throw new ArgumentNullException("userName"); } int result = 0; if (item.IsDirty) { QueryCommand cmd = ActiveHelper <T> .GetUpdateCommand(item, userName); result = DataService.ExecuteQuery(cmd); } item.DirtyColumns.Clear(); item.MarkOld(); item.MarkClean(); return(result); }
public int Insert <T>(RepositoryRecord <T> item, string userName) where T : RepositoryRecord <T>, new() { if (userName == null) { throw new ArgumentNullException("userName"); } int result = 0; QueryCommand cmd = ActiveHelper <T> .GetInsertCommand(item, userName); TableSchema.Table schema = item.GetSchema(); if (schema.PrimaryKey != null) { if (schema.PrimaryKey.AutoIncrement || schema.PrimaryKey.DataType == DbType.Guid) { object qResult = DataService.ExecuteScalar(cmd); item.SetColumnValue(schema.PrimaryKey.ColumnName, qResult); if (qResult != null) { int.TryParse(qResult.ToString(), out result); } } else { result = DataService.ExecuteQuery(cmd); } } else { result = DataService.ExecuteQuery(cmd); } item.DirtyColumns.Clear(); item.MarkOld(); item.MarkClean(); return(result); }