Пример #1
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());
        }
Пример #2
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);
        }
Пример #3
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());
        }