public void CacheTest() { var people = new People() { Id = 1, Name = "a" }; GenericCache <People> .GetOrSet(() => people); GenericCache <People> .Set(people); GenericCache <People> .Get(); }
/// <summary> /// /// </summary> /// <param name="dto"></param> /// <returns></returns> public PublicResult <PagedQueryArticles> PagedQueryArticles(PagedQueryArticleDto dto) { var page = dto.Page ?? 1; var pageSize = dto.PageSize ?? 20; ArticleModel model = null; using (var client = DbFactory.CreateClient()) { model = client.Queryable <ArticleModel>().InSingle(dto.ArticleModelId); } if (model == null) { return(Error("找不到文章模型")); } //设置字段 var articleProperties = GenericCache <ArticleTypeInfo> .GetOrSet(() => new ArticleTypeInfo { PropertyInfos = typeof(Article).GetProperties() }) .PropertyInfos; var configs = JsonConvert.DeserializeObject <List <ArticleConfiguration> >(model.Configuration); var selectFields = configs.Where(it => it.IsEnable && it.IsShowedInList) .Select(it => { var sugarColumn = articleProperties .FirstOrDefault(x => x.Name.Equals(it.FiledName, StringComparison.OrdinalIgnoreCase)) ?.GetCustomAttribute <SugarColumn>(); return(sugarColumn == null ? it.FiledName : sugarColumn.ColumnName); }).ToArray().Join(","); selectFields += selectFields.IsNullOrEmpty() ? "id,category_id" : ",id,category_id"; using (var client = DbFactory.CreateClient()) { var total = 0; var query = client.Queryable <Article>() .Where(it => it.ArticleTypeId == dto.ArticleModelId); if (dto.CategoryId > 0) { var queryChildrenIdsByParentIdResult = _categoryService.QueryChildrenIdsByParentId(dto.CategoryId, true); if (queryChildrenIdsByParentIdResult.Code == 0 && queryChildrenIdsByParentIdResult.Data != null && queryChildrenIdsByParentIdResult.Data.Any()) { query = query.Where(it => queryChildrenIdsByParentIdResult.Data.Contains(it.CategoryId.Value)); } } query = query.Select(selectFields); var list = query .OrderBy("id DESC") .ToPageList(page, pageSize, ref total); return(new PagedQueryArticles() { List = list.Select(it => new QueryArticleItem { Id = it.Id, CategoryId = it.CategoryId, Title = it.Title, SubTitle = it.SubTitle, TitleColor = it.TitleColor, TitleBold = it.TitleBold, Summary = it.Summary, Content = it.Content, Tags = it.Tags, ThumbImage = it.ThumbImage.GetFullPath(), Video = it.Video, Source = it.Source, Author = it.Author, Hits = it.Hits, Addtime = it.Addtime, OrderIndex = it.OrderIndex, IsTop = it.IsTop, IsRecommend = it.IsRecommend, SeoTitle = it.SeoTitle, SeoKeyword = it.SeoKeyword, SeoDescription = it.SeoDescription, String1 = it.String1, String2 = it.String2, String3 = it.String3, String4 = it.String4, Int1 = it.Int1, Int2 = it.Int2, Int3 = it.Int3, Int4 = it.Int4, Decimal1 = it.Decimal1, Decimal2 = it.Decimal2, Decimal3 = it.Decimal3, Decimal4 = it.Decimal4, Datetime1 = it.Datetime1, Datetime2 = it.Datetime2, Datetime3 = it.Datetime3, Datetime4 = it.Datetime4, Bool1 = it.Bool1, Bool2 = it.Bool2, Bool3 = it.Bool3, Bool4 = it.Bool4, Text1 = it.Text1, Text2 = it.Text2, Text3 = it.Text3, Text4 = it.Text4 }).ToList(), Page = page, PageSize = pageSize, TotalCount = total }); } }