예제 #1
0
        /// <summary>
        /// 会排除自动增长列
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connInfo"></param>
        /// <param name="Record"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public static int InsertPrimitive <T>(this DbContext connInfo, IEnumerable <T> records, SqlFunction repl = null, IEnumerable <string> onlyFields = null, string tableName = "")
            where T : new()
        {
            string sql = connInfo.GetInsertSql <T>(repl, onlyFields, tableName);

            if (connInfo.DbType != DbConnType.ODPNET)
            {
                return(connInfo.Db.Execute(sql, records, connInfo.Transaction, commandType: CommandType.Text));
            }
            else
            {
                Type      t       = typeof(T);
                TableInfo tblInfo = EntityReader.GetEntityMapping(t, true);
                Dictionary <string, PropertyInfo> fields = tblInfo.PropertyMappings;
                int count = 0;
                foreach (T record in records)
                {
                    RequestBase param = new RequestBase();
                    foreach (KeyValuePair <string, PropertyInfo> item in fields)
                    {
                        if (tblInfo.IsCurrentTimeField(item.Key) ||
                            (null != repl && repl.ExistsField(item.Key)))
                        {
                            continue;
                        }
                        param.Add(item.Key, SqlBuilder.GetPropertyValue <T>(record, item, connInfo.DbType));
                    }
                    count += connInfo.Db.Execute(sql, param, connInfo.Transaction, commandType: CommandType.Text);
                }
                return(count);
            }
        }