var categoriesEntities = new List<CategoryEntity>();
var allCategories = GetCategories();
var postCategoryMappings = _postCategoryMapping.Where(m => m.PostID == postID).ToList();
postCategoryMappings.ForEach(mapping =>
{
var category = allCategories.Single(c => c.CategoryID == mapping.CategoryID);
var categoryEntity = new CategoryEntity { CategoryID = mapping.CategoryID, CategoryName = category.CategoryName, CategorySlug = category.CategorySlug };
categoriesEntities.Add(categoryEntity);
});
本文介绍了一种将文章与类别进行映射的方法,通过遍历已有的类别集合并根据每篇文章的类别ID来创建新的类别实体对象。

被折叠的 条评论
为什么被折叠?



