Example #1
0
        public DataTable FindTable <T, FindT>(FindT FindEntity, string orderField, bool isAsc, int pageSize, int pageIndex, out int total, string appendSql = "")
            where FindT : class, new()
        {
            string sql                   = DatabaseCommon.QueryWhereSQL <FindT>(FindEntity).ToString();
            Type   type                  = FindEntity.GetType();
            string viewName              = "";
            var    viewAttribute         = type.GetCustomAttributes(true).OfType <ViewAttribute>();
            var    descriptionAttributes = viewAttribute as ViewAttribute[] ?? viewAttribute.ToArray();

            if (descriptionAttributes.Any())
            {
                viewName = descriptionAttributes.ToList()[0].viewName;
            }
            string tableName     = string.IsNullOrWhiteSpace(viewName) ? EntityAttribute.GetEntityTable <T>() : viewName;
            var    translateInfo = DatabaseCommon.GetTranslateValue <T>();

            if (translateInfo.Count(x => x.Length > 0) > 0)
            {
                sql = DatabaseCommon.PottingSql <T>(translateInfo, sql, tableName, string.IsNullOrWhiteSpace(viewName) ? false : true);
            }
            if (!string.IsNullOrEmpty(appendSql))
            {
                sql += appendSql;
            }
            return(FindTable(sql, orderField, isAsc, pageSize, pageIndex, out total));
        }
Example #2
0
        public IQueryable <T> IQueryable <T>(string sql) where T : class, new()
        {
            string tablename = EntityAttribute.GetEntityTable <T>();

            using (var dbConnection = Connection)
            {
                var translateInfo = DatabaseCommon.GetTranslateValue <T>();
                if (translateInfo.Count(x => x.Length > 0) > 0)
                {
                    sql = DatabaseCommon.PottingSql <T>(translateInfo, sql, tablename);
                }
                var data = dbConnection.Query <T>(sql);
                return(data.AsQueryable());
            }
        }