Exemple #1
0
        /// <summary>
        /// 查询数据.
        /// 若不分页查询,并且条件集为null, 并且类型特性上说明缓存的, 则走缓存。
        /// 否则直接从数据库中查询, 不走缓存。
        /// </summary>
        /// <typeparam name="T">类型值</typeparam>
        /// <param name="sqlCriteria">条件集</param>
        /// <param name="orderbyClause">排序集</param>
        /// <param name="pageIndex">起始页</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="recordCount">结果集大小</param>
        /// <returns>结果集</returns>
        public List <T> Query <T>(SqlCriteria sqlCriteria, string orderbyClause,
                                  int pageIndex, int pageSize, ref int recordCount)
            where T : class
        {
            //if (string.IsNullOrEmpty(orderbyClause))
            //{
            //    orderbyClause = OrmUtil.GetIdentityColumnName<T>();
            //}

            List <T> list      = new List <T>();
            string   tableName = OrmUtil.GetTableName <T>();

            if (OrmUtil.CheckCacheFlag <T>())
            {
                RegisterCacheTable(tableName, true);
            }

            DataTable dataTable = Query(tableName, "*", sqlCriteria, orderbyClause, pageIndex, pageSize, ref recordCount);

            if (dataTable != null)
            {
                list = ConvertUtil.ConvertDataToObject <T>(dataTable);
            }

            return(list);
        }
Exemple #2
0
        /// <summary>
        /// 保存数据。
        /// 默认的表名就是类名, 若T类型上有指定的表名,则以此为准
        /// 默认的自增列为Id,若T类型上有指定的自增列, 则以此为准。
        /// 若value中的标识列大于0, 则修改。 若小于等于0, 则新增。
        /// 注:主键为int
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="value">类型值</param>
        /// <returns>新增则返回自增列, 修改则返回本身标示列值。</returns>
        public int Save <T>(T value) where T : class
        {
            ThrowExceptionUtil.ArgumentNotNull(value, "value");

            string identityColumnName = OrmUtil.GetIdentityColumnName <T>();

            string tableName = OrmUtil.GetTableName <T>();

            EntityProxy <T> entityProxy = EntityProxyManager.Instance.GetEntityProxy <T>();

            object identity = entityProxy.GetPropertyValue(value, identityColumnName);

            ThrowExceptionUtil.ArgumentConditionTrue(identity != null, string.Empty, "未指定主键列");

            if ((int)identity <= 0)
            {
                return(Insert <T>(value));
            }
            else
            {
                BeeDataAdapter dataAdapter = BeeDataAdapter.From <T>(value);
                dataAdapter.RemoveKey(identityColumnName);

                Update(tableName, dataAdapter, SqlCriteria.New.Equal(identityColumnName, identity));

                return((int)identity);
            }
        }
Exemple #3
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="sqlCriteria">条件集</param>
        public void Delete <T>(SqlCriteria sqlCriteria)
            where T : class
        {
            string tableName = OrmUtil.GetTableName <T>();

            DeleteBeeCommand deleteBeeCommand = new DeleteBeeCommand(this, tableName, sqlCriteria);

            deleteBeeCommand.Excute <int>();
        }
Exemple #4
0
        /// <summary>
        /// 新增数据。
        /// 默认的表名就是类名, 若T类型上有指定的表名,则以此为准
        /// 默认的自增列为Id,若T类型上有指定的自增列, 则以此为准。
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="value">类型值</param>
        /// <param name="removeIdentity">是否移除标示列,该值若为false, 则Insert语句中将可能包含自增列。</param>
        /// <returns>插入返回的自增列</returns>
        public int Insert <T>(T value, bool removeIdentity) where T : class
        {
            ThrowExceptionUtil.ArgumentNotNull(value, "value");

            Type            typeInfo    = typeof(T);
            EntityProxy <T> entityProxy = EntityProxyManager.Instance.GetEntityProxy <T>();

            string tableName          = OrmUtil.GetTableName <T>();
            string identityColumnName = OrmUtil.GetIdentityColumnName <T>();

            BeeDataAdapter dataAdapter = BeeDataAdapter.From <T>(value);

            int result = Insert(tableName, dataAdapter, removeIdentity);

            if (result != -1)
            {
                entityProxy.SetPropertyValue(value, identityColumnName, result);
            }

            return(result);
        }