using MediatR;using TodoList.Application.Common.Interfaces;using TodoList.Domain.ValueObjects;namespace TodoList.Application.TodoLists.Commands.CreateTodoList;public class CreateTodoListCommand : IRequest<Domain.Entities.TodoList>{public string? Title { get; set; }public string? Colour { get; set; ...
问使用Automapper映射列表ENList<Person>people=newList<Person>();List<PersonViewModel>peopelVM;peopel...
因为这个示例项目只是为了演示如何在 ASP.NET Core 项目中去使用 AutoMapper,所以这里并没有进行分层,整个示例页面的运行流程就是,PostController 中的 List Action 调用 PostAppService 类中的 GetPostLists 方法去获取所有的文章数据,同时在这个方法中会进行实体映射,将我们从 PostDomain 中获取到的 PO 对象转换成页...
varpersons =newList<Person>{newPerson { Name ="张三", Age =18},newPerson { Name ="李四", Age =20},newPerson { Name ="王五", Age =22} };varpersonDtos = persons.Select(p => Mapper.Map<PersonDto>(p)).ToList(); 在上面的示例中,我们使用Select方法对persons列表进行投影映射,自动将Pe...
public static List<TDestination> MapToList<TDestination>(this IEnumerable source) { foreach (var first in source) { var type = first.GetType(); Mapper.CreateMap(type, typeof(TDestination)); break; } return Mapper.Map<List<TDestination>>(source); ...
public class FooDto { public int ID { get; set; } public string Name { get; set; } } public void Map() { var config = new MapperConfiguration(cfg => cfg.CreateMap()); var mapper = config.CreateMapper(); Foo foo = new Foo { ID = 1, Name = "Tom" }; ...
var SMList = context.Student.Include(A=>A.Dept).Where(A => A.StuName.Contains("陈")).ToList(); AutoMapper.Mapper.CreateMap<Student, StudentModel>() .ForMember(dest => dest.deptName, opts => opts.MapFrom(src => src.Dept.deptName)); ...
privateIList<OrderLine> _lineItems =newList<OrderLine>(); publicOrderLine[] LineItems {get{return_lineItems.ToArray(); } } publicvoidAddLineItem(OrderLine orderLine) { _lineItems.Add(orderLine); } } publicclassOrderLine { publicintQuantity {get;set; } ...
().ToFullString(); var toTypeArgSyntax = attr.ArgumentList.Arguments.ElementAt(1); var toTypeArgSyntaxExpr = toTypeArgSyntax.Expression.NormalizeWhitespace().ToFullString(); var fromClassName = GetContentInParentheses(fromTypeArgSyntaxExpr); var fromClassSyntax = allClasses.First(x => x....
public static List<TDestination> MapToList<TDestination>(this IEnumerable source) { foreach (var first in source) { var type = first.GetType(); Mapper.CreateMap(type, typeof(TDestination)); break; } return Mapper.Map<List<TDestination>>(source); ...