Dtcms8对sqlite数据库支持的错误修复:Dtcms.Core.Services项目,ArticleCategoryService.cs文件,QueryArticleListAsync方法。
/// <summary>
/// 根据父ID返回一级列表(缓存带文章)
/// </summary>
public async Task<IEnumerable<ArticleCategorysClientDto>> QueryArticleListAsync(string cacheKey, int channelId, int categoryTop, int articleTop, int status,
Expression<Func<Articles, bool>> funcWhere, string orderBy)
{
string className = typeof(ArticleCategorys).Name; //获取类名的字符串
string classKey = $"{className}:List:{cacheKey}";
return await _cacheService.GetOrSetAsync(classKey, async () =>
{
_context = _contextFactory.CreateContext(WriteRoRead.Read);//连接数据库
var query = _context.Set<ArticleCategorys>()
.Where(x => x.ChannelId == channelId && x.ParentId == 0 && (status == -1 || x.Status == status))
.OrderByBatch(orderBy)
.Take(categoryTop)
.ToList() //修复错误添加
.Select(c => new
{
Category = c,
Article = _context.Set<Articles>()
.Include(x => x.ArticleGroups)
//.Include(x => x.ArticleAlbums)
.Include(x => x.CategoryRelations)
.Where(x => x.CategoryRelations.Any(r => r.CategoryId == c.Id))
.Where(funcWhere)
.OrderBy(x => x.SortId)
.Take(articleTop)
.ToList()
})
.Select(ca => new ArticleCategorysClientDto
{
Id = ca.Category.Id,
Title = ca.Category.Title,
ImgUrl = ca.Category.ImgUrl,
Data = ca.Article.Select(x => new ArticlesClientDto
{
Id = x.Id,
CallIndex = x.CallIndex,
Title = x.Title,
Source = x.Source,
Zhaiyao = x.Zhaiyao,
ImgUrl = x.ImgUrl,
VideoUrl = x.VideoUrl,
Click = x.Click,
CommentCount = x.CommentCount,
LikeCount = x.LikeCount,
SortId = x.SortId,
AddTime = x.AddTime,
/*ArticleAlbums = x.ArticleAlbums.Select(ab => new ArticleAlbumsDto
{
Id = ab.Id,
ArticleId = ab.ArticleId,
ThumbPath = ab.ThumbPath,
OriginalPath = ab.OriginalPath,
Remark = ab.Remark,
AddTime = ab.AddTime,
SortId = ab.SortId
})*/
})
});
return query.ToList();
}) ?? [];
}


