public void Destroy <T>(RepositoryRecord <T> item) where T : RepositoryRecord <T>, new() { TableSchema.Table tbl = item.GetSchema(); string pkColumn = tbl.PrimaryKey.ColumnName; object pkValue = item.GetColumnValue(pkColumn); new Destroy().From(tbl).Where(pkColumn).IsEqualTo(pkValue).Execute(); }
public void Delete <T>(RepositoryRecord <T> item) where T : RepositoryRecord <T>, new() { TableSchema.Table tbl = item.GetSchema(); string pkColumn = tbl.PrimaryKey.ColumnName; object pkValue = item.GetColumnValue(pkColumn); Delete <T>(pkColumn, pkValue); }
/// <summary> /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>. /// </summary> /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param> /// <returns> /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false. /// </returns> /// <exception cref="T:System.NullReferenceException">The <paramref name="obj"/> parameter is null.</exception> public override bool Equals(object obj) { RepositoryRecord <T> repositoryObj = obj as RepositoryRecord <T>; if (repositoryObj != null) { return(GetPrimaryKeyValue().Equals(repositoryObj.GetPrimaryKeyValue())); } return(base.Equals(obj)); }
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 Save <T>(RepositoryRecord <T> item, string userName) where T : RepositoryRecord <T>, new() { //validation item.ValidateColumnSettings(); if (item.HasErrors()) { StringBuilder sb = new StringBuilder(); List <string> errors = item.GetErrors(); foreach (string error in errors) { sb.Append(error + Environment.NewLine); } throw new SqlQueryException("There are errors saving this item: " + sb); } int result = item.IsNew ? Insert(item, userName) : Update(item, userName); 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); }
public int Insert <T>(RepositoryRecord <T> item) where T : RepositoryRecord <T>, new() { return(Insert(item, String.Empty)); }
public int Update <T>(RepositoryRecord <T> item) where T : RepositoryRecord <T>, new() { return(Update(item, String.Empty)); }