Пример #1
0
        public static GXInsertArgs Insert <T>(T value, Expression <Func <T, object> > columns)
        {
            if (value is GXSelectArgs)
            {
                return(Insert <T>(value as GXSelectArgs));
            }
            if (value is GXInsertArgs)
            {
                throw new ArgumentException("Can't insert GXInsertArgs.");
            }
            if (value == null)
            {
                throw new ArgumentNullException("Inserted item can't be null.");
            }
            if (value is IEnumerable)
            {
                throw new ArgumentException("Use InsertRange to add a collection.");
            }
            if (value is GXTableBase tb)
            {
                tb.BeforeAdd();
            }
            GXInsertArgs args = new GXInsertArgs();

            args.Parent.Updated = true;
            args.Values.Add(new KeyValuePair <object, LambdaExpression>(value, columns));
            return(args);
        }
Пример #2
0
        /// <summary>
        /// Copy rows from the table
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="select"></param>
        /// <returns></returns>
        public static GXInsertArgs Insert <T>(GXSelectArgs select, Expression <Func <T, object> > columns)
        {
            GXInsertArgs args = new GXInsertArgs();

            select.Parent.Settings = args.Parent.Settings;
            args.Add(select, columns);
            return(args);
        }
Пример #3
0
        /// <summary>
        /// Copy rows from the same table.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="select"></param>
        /// <returns></returns>
        public static GXInsertArgs Insert <T>(GXSelectArgs select)
        {
            GXInsertArgs args = new GXInsertArgs();

            select.Parent.Settings = args.Parent.Settings;
            args.Parent.Updated    = true;
            Expression <Func <T, object> > expression = _ => typeof(T);

            args.Values.Add(new KeyValuePair <object, LambdaExpression>(select, expression));
            return(args);
        }
Пример #4
0
        public static GXInsertArgs InsertRange <T>(IEnumerable <T> collection, Expression <Func <T, object> > columns)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("Inserted item can't be null.");
            }
            GXInsertArgs args = new GXInsertArgs();

            args.Parent.Updated = true;
            foreach (var it in collection)
            {
                args.Values.Add(new KeyValuePair <object, LambdaExpression>(it, columns));
            }
            return(args);
        }
Пример #5
0
        public static GXInsertArgs Add <TItem, TDestination>(TItem[] items, TDestination[] collections)
        {
            object collectionId, id;

            if (items == null || collections == null || items.Length == 0 || collections.Length == 0)
            {
                throw new ArgumentNullException("Invalid value");
            }
            Type             itemType       = typeof(TItem);
            Type             collectionType = typeof(TDestination);
            GXSerializedItem si             = GXSqlBuilder.FindRelation(itemType, collectionType);

            if (si.Relation == null || si.Relation.RelationMapTable == null)
            {
                throw new ArgumentNullException("Invalid collection");
            }
            GXInsertArgs args = new GXInsertArgs();

            args.Parent.Updated = true;
            GXSerializedItem siItem = GXSqlBuilder.FindRelation(collectionType, itemType);

            foreach (TDestination c in collections)
            {
                //Get collection id.
                collectionId = si.Relation.RelationMapTable.Relation.ForeignId.Get(c);
                foreach (TItem it in items)
                {
                    object target = GXJsonParser.CreateInstance(si.Relation.RelationMapTable.Relation.PrimaryTable);
                    si.Relation.RelationMapTable.Relation.PrimaryId.Set(target, collectionId);
                    //Get item id.
                    id = siItem.Relation.RelationMapTable.Relation.ForeignId.Get(it);
                    siItem.Relation.RelationMapTable.Relation.PrimaryId.Set(target, id);
                    args.Values.Add(new KeyValuePair <object, LambdaExpression>(target, null));
                }
            }
            return(args);
        }