コード例 #1
0
        /// <summary>
        /// The SimpleInsert.
        /// </summary>
        /// <param name="table">The table<see cref="IFigures"/>.</param>
        /// <param name="buildMapping">The buildMapping<see cref="bool"/>.</param>
        /// <param name="batchSize">The batchSize<see cref="int"/>.</param>
        /// <returns>The <see cref="int"/>.</returns>
        public int SimpleInsert(IFigures table, bool buildMapping, int batchSize = 1000)
        {
            try
            {
                IFigures             tab   = table;
                IList <FieldMapping> nMaps = new List <FieldMapping>();
                SqlAdapter           afad  = new SqlAdapter(_cn);
                StringBuilder        sb    = new StringBuilder();
                int intSqlset = 0;
                sb.AppendLine(@"  /* ----  SQL BANK START CMD ------ */  ");
                int count = 0;
                foreach (IFigure ir in tab)
                {
                    foreach (FieldMapping nMap in nMaps)
                    {
                        ;
                        MemberRubric[] ic = tab.Rubrics.AsValues().Where(c => nMap.ColumnOrdinal.Contains(c.FieldId)).ToArray();
                        MemberRubric[] ik = tab.Rubrics.AsValues().Where(c => nMap.KeyOrdinal.Contains(c.FieldId)).ToArray();

                        string qry = BatchInsertQuery(ir, nMap.DbTableName, ic, ik).ToString();
                        sb.Append(qry);
                        count++;
                    }
                    if (count >= batchSize)
                    {
                        sb.AppendLine(@"  /* ----  DATA BATCH END CMD ------ */  ");

                        intSqlset += afad.ExecuteInsert(sb.ToString());

                        sb.Clear();
                        sb.AppendLine(@"  /* ----  SQL BANK START CMD ------ */  ");
                        count = 0;
                    }
                }
                sb.AppendLine(@"  /* ----  DATA BANK END CMD ------ */  ");

                intSqlset += afad.ExecuteInsert(sb.ToString());
                return(intSqlset);
            }
            catch (SqlException ex)
            {
                _cn.Close();
                throw new SqlInsertException(ex.ToString());
            }
        }
コード例 #2
0
        /// <summary>
        /// The BatchInsert.
        /// </summary>
        /// <param name="table">The table<see cref="IFigures"/>.</param>
        /// <param name="buildMapping">The buildMapping<see cref="bool"/>.</param>
        /// <param name="batchSize">The batchSize<see cref="int"/>.</param>
        /// <returns>The <see cref="IDeck{IDeck{IFigure}}"/>.</returns>
        public IDeck <IDeck <IFigure> > BatchInsert(IFigures table, bool buildMapping, int batchSize = 1000)
        {
            try
            {
                IFigures                 tab   = table;
                IList <FieldMapping>     nMaps = new List <FieldMapping>();
                SqlAdapter               afad  = new SqlAdapter(_cn);
                StringBuilder            sb    = new StringBuilder();
                IDeck <IDeck <IFigure> > nSet  = new Album <IDeck <IFigure> >();
                sb.AppendLine(@"  /* ----  SQL BANK START CMD ------ */  ");
                int count = 0;
                foreach (IFigure ir in tab)
                {
                    foreach (FieldMapping nMap in nMaps)
                    {
                        MemberRubric[] ic = tab.Rubrics.AsValues().Where(c => nMap.ColumnOrdinal.Contains(c.FieldId)).ToArray();
                        MemberRubric[] ik = tab.Rubrics.AsValues().Where(c => nMap.KeyOrdinal.Contains(c.FieldId)).ToArray();

                        string qry = BatchInsertQuery(ir, nMap.DbTableName, ic, ik).ToString();
                        sb.Append(qry);
                        count++;
                    }
                    if (count >= batchSize)
                    {
                        sb.AppendLine(@"  /* ----  DATA BATCH END CMD ------ */  ");
                        var bIFigures = afad.ExecuteInsert(sb.ToString(), tab);
                        if (nSet.Count == 0)
                        {
                            nSet = bIFigures;
                        }
                        else
                        {
                            foreach (Album <IFigure> its in bIFigures.AsValues())
                            {
                                if (nSet.Contains(its))
                                {
                                    nSet[its].Put(its.AsValues());
                                }
                                else
                                {
                                    nSet.Add(its);
                                }
                            }
                        }
                        sb.Clear();
                        sb.AppendLine(@"  /* ----  SQL BANK START CMD ------ */  ");
                        count = 0;
                    }
                }
                sb.AppendLine(@"  /* ----  DATA BANK END CMD ------ */  ");

                var rIFigures = afad.ExecuteInsert(sb.ToString(), tab);

                if (nSet.Count == 0)
                {
                    nSet = rIFigures;
                }
                else
                {
                    foreach (IDeck <IFigure> its in rIFigures.AsValues())
                    {
                        if (nSet.Contains(its))
                        {
                            nSet[its].Put(its.AsValues());
                        }
                        else
                        {
                            nSet.Add(its);
                        }
                    }
                }

                return(nSet);
            }
            catch (SqlException ex)
            {
                _cn.Close();
                throw new SqlInsertException(ex.ToString());
            }
        }
コード例 #3
0
        /// <summary>
        /// The BulkInsert.
        /// </summary>
        /// <param name="table">The table<see cref="IFigures"/>.</param>
        /// <param name="keysFromDeckis">The keysFromDeckis<see cref="bool"/>.</param>
        /// <param name="buildMapping">The buildMapping<see cref="bool"/>.</param>
        /// <param name="updateKeys">The updateKeys<see cref="bool"/>.</param>
        /// <param name="updateExcept">The updateExcept<see cref="string[]"/>.</param>
        /// <param name="tempType">The tempType<see cref="BulkPrepareType"/>.</param>
        /// <returns>The <see cref="IDeck{IDeck{IFigure}}"/>.</returns>
        public IDeck <IDeck <IFigure> > BulkInsert(IFigures table, bool keysFromDeckis = false, bool buildMapping = false, bool updateKeys = false, string[] updateExcept = null, BulkPrepareType tempType = BulkPrepareType.Trunc)
        {
            try
            {
                IFigures tab = table;
                if (tab.Any())
                {
                    IList <FieldMapping> nMaps = new List <FieldMapping>();
                    if (buildMapping)
                    {
                        SqlMapper imapper = new SqlMapper(tab, keysFromDeckis);
                    }
                    nMaps = tab.Rubrics.Mappings;
                    string     dbName = _cn.Database;
                    SqlAdapter afad   = new SqlAdapter(_cn);
                    afad.DataBulk(tab, tab.FigureType.Name, tempType, BulkDbType.TempDB);
                    _cn.ChangeDatabase(dbName);
                    IDeck <IDeck <IFigure> > nSet = new Album <IDeck <IFigure> >();

                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine(@"  /* ----  SQL BANK START CMD ------ */  ");
                    foreach (FieldMapping nMap in nMaps)
                    {
                        sb.AppendLine(@"  /* ----  TABLE BULK START CMD ------ */  ");

                        MemberRubric[] ic = tab.Rubrics.AsValues().Where(c => nMap.ColumnOrdinal.Contains(c.FieldId)).ToArray();
                        MemberRubric[] ik = tab.Rubrics.AsValues().Where(c => nMap.KeyOrdinal.Contains(c.FieldId)).ToArray();

                        if (updateExcept != null)
                        {
                            ic = ic.Where(c => !updateExcept.Contains(c.RubricName)).ToArray();
                            ik = ik.Where(c => !updateExcept.Contains(c.RubricName)).ToArray();
                        }

                        string qry = BulkInsertQuery(dbName, tab.FigureType.Name, nMap.DbTableName, ic, ik, updateKeys).ToString();
                        sb.Append(qry);
                        sb.AppendLine(@"  /* ----  TABLE BULK END CMD ------ */  ");
                    }
                    sb.AppendLine(@"  /* ----  SQL BANK END CMD ------ */  ");

                    IDeck <IDeck <IFigure> > bIFigures = afad.ExecuteInsert(sb.ToString(), tab, true);


                    if (nSet.Count == 0)
                    {
                        nSet = bIFigures;
                    }
                    else
                    {
                        foreach (IDeck <IFigure> its in bIFigures.AsValues())
                        {
                            if (nSet.Contains(its))
                            {
                                nSet[its].Put(its.AsValues());
                            }
                            else
                            {
                                nSet.Add(its);
                            }
                        }
                    }
                    sb.Clear();

                    return(nSet);
                }
                else
                {
                    return(null);
                }
            }
            catch (SqlException ex)
            {
                _cn.Close();
                throw new SqlInsertException(ex.ToString());
            }
        }