新的转换列表方式

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);
});

原文地址:https://www.cnblogs.com/opts/p/7753811.html