范例:Sample,不要加List</typeparam>/// <param name="source">源集合</param>publicstaticList<TDestination> MapToList<TDestination>( this System.Collections.IEnumerable source ) {returnMapTo<List<TDestination>>( source );
最近在研究AutoMapper,到Mapper.Map<List<MenuEntity>, List<MenuDto>>(list);总是返回结构数是0,而实际上list是有数据的 google了好久发现用ProjectTo可以 需添加 using AutoMapper.QueryableExtensions; 但是当我再次用先前的方法:return Mapper.Map<List<MenuEntity>, List<MenuDto>>(list); 时,又有返回值了 ...
public static ListMapToList(this IEnumerable source)41 {42 var mapper = _serviceProvider.GetRequiredService();43 return mapper.Map<List>(source);44 }45 } 1. 添加到Configure: 1 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)2 {3 app.UseStateAutoMapper();4 } 1. 使用:...
AutoMapper.Mapper.Initialize(map => map.CreateMap<student, v_student="">()); var stu = AutoMapper.Mapper.Map(new V_Student { Name = "myname", Sex = 1, Age = "24", Birth = DateTime.Now }); var vstu = AutoMapper.Mapper.Map<v_student>(new Student { Name = "myname", Sex = ...
spt_detail details = db.spt_detail.ToList(); Mapper.Initialize(n => n.CreateMap<List<spt_detail>, List<spt_detail_extended>>()); List<spt_creance_detail_enrichi> cenr = AutoMapper.Mapper.Map<List<spt_detail>, List<spt_detail_enrichi>>(details); ...
public static TDestination MapTo<TDestination, TSource>(this TSource source)where TDestination : class where TSource : class { if (source == null) return default(TDestination);var config = new MapperConfiguration(cfg => cfg.CreateMap<TSource, TDestination>());
publicasyncTask<List<OrderItemDTO>>QueryItem { varorderList =awaitdBContext.DB.Queryable<OrderItem>.ToListAsync; varorderDtoList = mapper.Map<List<OrderItemDTO>>(orderList); returnawaitTask.FromResult(orderDtoList); } } 7.实现效果 1)“数据模型”Order类型中的Name属性值 映射到 “视图模型”Ord...
(obj==null)returndefault(T);returnMapper.Map<T>(obj);}/// <summary>/// 集合列表类型映射-由AutoMapper创建目标对象/// </summary>publicstaticIEnumerable<TDestination>MapToList<TDestination>(thisIEnumerablesource){if(source==null)returnnewList<TDestination>();returnMapper.Map<IEnumerable<T...
首先我们需要创建一个实体映射的配置类,需要继承于 AutoMapper 的 Profile 类,在无参构造函数中,我们就可以通过 CreateMap 方法去创建两个实体间的映射关系。 代码语言:javascript 复制 publicclassPostProfile:Profile{/// <summary>/// ctor/// </summary>publicPostProfile(){// 配置 mapping 规则//CreateMap<...
"Parameter is not valid" - new Bitmap() "Recursive write lock acquisitions not allowed in this mode.? "Settings" in DLL project properties and app.config file "The function evaluation requires all threads to run" while accessing music library through wmp.dll "The left-hand side of an ...