Exemple #1
0
        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);
        }
Exemple #2
0
 /// <summary>
 /// Returns a INSERT QueryCommand object used to generate SQL.
 /// </summary>
 /// <param name="userName">An optional username to be used if audit fields are present</param>
 /// <returns></returns>
 public QueryCommand GetInsertCommand(string userName)
 {
     return(ActiveHelper <T> .GetInsertCommand(this, userName));
 }
 /// <summary>
 /// Made Public for use with transactions
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="userName">Name of the user.</param>
 /// <returns></returns>
 public static QueryCommand GetInsertCommand(ItemType item, string userName)
 {
     return(ActiveHelper <ItemType> .GetInsertCommand(item, userName));
 }