新的转换列表方式

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

posted @ 2017-10-30 11:40  !opts  阅读(239)  评论(0编辑  收藏  举报