Beispiel #1
0
        /// <summary>
        /// UPDATE table_name
        /// SET column1 = value, column2 = value,...
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <param name="customization"></param>
        /// <returns></returns>
        public UpdateStatement Update <T>(T obj, Action <Target, Context> customization = null)
        {
            UpdateStatement statement = null;

            if (obj is IEnumerable)
            {
                var enumerator = ((IEnumerable)obj).GetEnumerator();

                while (enumerator.MoveNext())
                {
                    if (statement == null)
                    {
                        statement = new UpdateStatement(new Table(enumerator.Current.GetType()));
                    }

                    statement.ObjectList.Add(enumerator.Current);
                }
            }
            else
            {
                statement = new UpdateStatement(new Table(typeof(T)));
                statement.ObjectList.Add(obj);
            }

            Statement = statement;
            statement.Target.Customize(customization);

            return(statement);
        }
Beispiel #2
0
        /// <summary>
        /// UPDATE table_name
        /// SET column1 = value, column2 = value,...
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <param name="customization"></param>
        /// <returns></returns>
        public UpdateStatement Update <T>(T obj, Action <Target, Context> customization = null) where T : class, new()
        {
            var statement = new UpdateStatement(new Table <T>());

            statement.ObjectList.Add(obj);
            statement.Target.Customize(customization);
            Statement = statement;

            return(statement);
        }
Beispiel #3
0
        /// <summary>
        /// UPDATE table_name
        /// SET column1 = value, column2 = value,...
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="objects"></param>
        /// <param name="customization"></param>
        /// <returns></returns>
        public UpdateStatement UpdateMany <T>(IEnumerable <T> objects, Action <Target, Context> customization = null) where T : class, new()
        {
            var statement  = new UpdateStatement(new Table <T>());
            var enumerator = ((IEnumerable)objects).GetEnumerator();

            while (enumerator.MoveNext())
            {
                statement.ObjectList.Add(enumerator.Current);
            }

            statement.Target.Customize(customization);
            Statement = statement;

            return(statement);
        }