예제 #1
0
        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();
        }
예제 #2
0
        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);
        }
예제 #3
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);
        }