Esempio n. 1
0
 // ---------------------------------------------------------------------
 // Insert
 // ---------------------------------------------------------------------
 public void Insert <T>(T model, String statement, IInsertable <T> traits)
 {
     using (SqlCommand cmd = new SqlCommand(statement, m_connection))
     {
         traits.ApplyInsert(model, cmd);
         cmd.ExecuteNonQuery();
     }
 }
Esempio n. 2
0
        public Task <T> ExecuteReturnEntityAsync()
        {
            Task <T> result = new Task <T>(() =>
            {
                IInsertable <T> asyncInsertable = CopyInsertable();
                return(asyncInsertable.ExecuteReturnEntity());
            });

            TaskStart(result);
            return(result);
        }
Esempio n. 3
0
        public Task <long> ExecuteReturnBigIdentityAsync()
        {
            Task <long> result = new Task <long>(() =>
            {
                IInsertable <T> asyncInsertable = CopyInsertable();
                return(asyncInsertable.ExecuteReturnBigIdentity());
            });

            result.Start();
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// 插入一个实体
        /// </summary>
        /// <typeparam name="T">表实体</typeparam>
        /// <param name="entity">实体内容</param>
        /// <param name="pk">要忽略的主键</param>
        /// <returns>本批次最大主键ID</returns>
        public long Add <T>(T[] entitys, Expression <Func <T, object> > pk = null) where T : class, new()
        {
            IInsertable <T> r = _db.Insertable(entitys);

            if (pk != null)
            {
                r = r.IgnoreColumns(pk);
            }

            return(r.ExecuteReturnIdentity());
        }
Esempio n. 5
0
        public Task <bool> ExecuteCommandIdentityIntoEntityAsync()
        {
            Task <bool> result = new Task <bool>(() =>
            {
                IInsertable <T> asyncInsertable = CopyInsertable();
                return(asyncInsertable.ExecuteCommandIdentityIntoEntity());
            });

            result.Start();
            return(result);
        }
Esempio n. 6
0
        public Task <int> ExecuteCommandAsync()
        {
            Task <int> result = new Task <int>(() =>
            {
                IInsertable <T> asyncInsertable = CopyInsertable();
                return(asyncInsertable.ExecuteCommand());
            });

            result.Start();
            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// 批量新增实体
        /// </summary>
        /// <typeparam name="T">表实体</typeparam>
        /// <param name="entitys">实体集合,List<T></param>
        /// <param name="ignorePk">要忽略的主键</param>
        /// <returns>最大id</returns>
        public long Insert <T>(T[] entitys, Expression <Func <T, object> > ignorePk = null) where T : class, new()
        {
            IInsertable <T> insertObj = _db.Insertable(entitys);

            if (ignorePk != null)
            {
                insertObj = insertObj.IgnoreColumns(ignorePk);
            }
            var t = insertObj.ExecuteReturnBigIdentityAsync();

            t.Wait();
            return(t.Result);
        }
Esempio n. 8
0
        public int Insert <T>(T entity, Expression <Func <T, object> > pk = null, bool isIdentity = true) where T : class, new()
        {
            IInsertable <T> insertObj = _db.Insertable(entity);

            if (pk != null)
            {
                insertObj = insertObj.IgnoreColumns(pk);
            }
            if (isIdentity)
            {
                return(insertObj.ExecuteReturnIdentity());
            }
            return(insertObj.ExecuteCommand());
        }
Esempio n. 9
0
        /// <summary>
        /// 设置需新增的字段和值
        /// </summary>
        /// <param name="source">source</param>
        /// <param name="property">字段</param>
        /// <param name="value">值</param>
        public static IInsertable Set(this IInsertable source, MemberExpression property, object value)
        {
            var key = source.Properties.Keys.Where(s => s.MemberExpressionEqual(property)).FirstOrDefault();

            if (key == null)
            {
                source.Properties.Add(property, value);
            }
            else
            {
                source.Properties[key] = value;
            }

            return(source);
        }
Esempio n. 10
0
        /**
         * Create a new {@code AnimateAdditionAdapter} with given {@link android.widget.BaseAdapter}.
         *
         * @param baseAdapter should implement {@link Insertable},
         *                    or be a {@link com.nhaarman.listviewanimations.BaseAdapterDecorator} whose BaseAdapter implements the interface.
         */
        public AnimateAdditionAdapter(BaseAdapter baseAdapter)
            : base(baseAdapter)
        {
            //super(baseAdapter);

            BaseAdapter rootAdapter = getRootAdapter();

            if (!(rootAdapter is IInsertable))
            {
                throw new Java.Lang.IllegalArgumentException("BaseAdapter should implement Insertable!");
            }
            //mInsertable = (Insertable<T>) rootAdapter;
            mInsertable  = (IInsertable)rootAdapter;
            mInsertQueue = new InsertQueue <T>(mInsertable);
        }
        /// <summary>
        /// 设置需新增的字段和值
        /// </summary>
        /// <param name="source"></param>
        /// <param name="property">字段</param>
        /// <param name="value">值</param>
        /// <typeparam name="T">元素类型</typeparam>
        public static IInsertable <T> Set <T>(this IInsertable <T> source, Expression <Func <T, object> > property, object value)
        {
            MemberExpression me = property.Body.ToMemberExpression();

            var key = source.Properties.Keys.Where(s => s.MemberExpressionEqual(me)).FirstOrDefault();

            if (key == null)
            {
                source.Properties.Add(me, value);
            }
            else
            {
                source.Properties[key] = value;
            }

            return(source);
        }
Esempio n. 12
0
        // ---------------------------------------------------------------------
        // Insert
        // ---------------------------------------------------------------------
        public void Insert <T>(T model, String statement, IInsertable <T> traits)
        {
            using (IDbCommand command = m_connection.CreateCommand())
            {
                command.CommandText = statement;
                traits.ApplyInsert(model, command);
                command.ExecuteNonQuery();
            }

            IAutoNumberable <T> anTraits
                = traits is IAutoNumberable <T>
                  ?traits as IAutoNumberable <T>
                  : Orm.GetAutoNumberable <T>()
                ;

            if (anTraits != null)
            {
                anTraits.ApplyAutoNumber(model, GetLastInsertRowId());
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 将实体对象插入到数据库
        /// </summary>
        /// <param name="object">实体对象</param>
        public virtual int Insert(object @object)
        {
            IEntityObject entity = (IEntityObject)@object;

            Type elementType = @object.GetType().BaseType;

            IInsertable insertable = this.factory.CreateInsertProvider(this).CreateInsert(elementType);

            var properties = @object.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            properties.Where(property => property.IsAutoIncrease() == false).Each(property =>
            {
                if (entity.ChangedProperties.Contains(property.Name))
                {
                    ParameterExpression pe = Expression.Parameter(@object.GetType(), "s");
                    MemberExpression me    = Expression.MakeMemberAccess(pe, property);

                    insertable.Set(me, property.EmitGetValue(@object));
                }
            });

            return(insertable.Execute(elementType));
        }
Esempio n. 14
0
 public InsertQueue(IInsertable insertable)
 {
     mInsertable = insertable;
 }
Esempio n. 15
0
        /// <summary>
        ///     添加单个
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>主键ID</returns>
        public virtual async Task <bool> Add(T entity)
        {
            IInsertable <T> insert = this.SugarClient.Insertable(entity);

            return(await insert.ExecuteCommandIdentityIntoEntityAsync());
        }
Esempio n. 16
0
 public void Insert <T>(T model, IInsertable <T> traits)
 {
     Insert(model, traits.InsertSql(), traits);
 }
Esempio n. 17
0
 public static void RegisterInsert <T>(IInsertable <T> converter)
 {
     Init();
     m_insert_register[typeof(T)] = converter;
 }
 /// <summary>
 /// 执行指定类型元素的删除操作
 /// </summary>
 /// <param name="source">可新增的对象</param>
 /// <typeparam name="T">受影响的行数</typeparam>
 public static int Execute <T>(this IInsertable <T> source)
 {
     return(source.Provider.Execute <T>(source.Properties));
 }
Esempio n. 19
0
 /// <summary>
 /// 执行未指定元素类型的插入操作
 /// </summary>
 /// <param name="source">Source.</param>
 /// <param name="elementType">Element type.</param>
 public static int Execute(this IInsertable source, Type elementType)
 {
     return(source.Provider.Execute(elementType, source.Properties));
 }
Esempio n. 20
0
 public static IDelete Delete <TSource>(this IInsertable <TSource> source, TSource entity, params TSource[] entities)
 {
     return(new DeleteStatement(((ISourcable)source).GetDatabase(), entity, entities));
 }
Esempio n. 21
0
 public static IInsert InsertFrom <TSource>(this IInsertable <TSource> source, IQuery <TSource> from)
 {
     return(new InsertFromStatement <TSource>(((ISourcable)source).GetDatabase(), from));
 }
Esempio n. 22
0
 public void Add(IInsertable insertable)
 {
     _buffer.Post(insertable);
 }
Esempio n. 23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="able"></param>
 public SugarWInsertable(IInsertable <T> able)
 {
     _insertable = able;
 }