我在我的方法中使用了AutoMapper但是没有用。 请帮我纠正。
public virtual IEnumerable<TViewModel> FindAllByCriteria(Expression<Func<TModel, bool>> predicate = null, params Expression<Func<TModel, object>>[] includeProperties)
{
IQueryable<TModel> items = RepositoryContainer<TRepository>().FindAll();
if (includeProperties != null)
{
foreach (var includeProperty in includeProperties)
{
items = items.Include(includeProperty);
}
}
var destination_VMList = new List<TViewModel>();
var source_tModelList = new List<TModel>();
source_tModelList = predicate != null ? items.Where(predicate).ToList() : items.ToList();
Mapper.Map(source_tModelList, destination_VMList); // Error happened!
return destination_VMList;
}
错误讯息:
Missing type map configuration or unsupported mapping.
Mapping types:
Tag -> TagViewModel
Jahan.Blog.Model.Tag -> Jahan.Blog.ViewModel.TagViewModel
Destination path:
List`1[0]
Source value:
System.Data.Entity.DynamicProxies.Tag_F1F5C39705DF9507B542CCC1A519D0757945F8E00B19F4F20C89F81DF8358563
答案 0 :(得分:0)
您必须先配置地图:
Mapper.CreateMap<Tag , TagViewModel>();
然后你可以这样映射:
var destination_VMList = Mapper.Map<IEnumerable<TModel>, IEnumerable<TViewModel>>(source_tModelList);