映射器ResolutionContext _mapper.Map<List<T>>(filterList, opts => opts.Items["uıFilter"] = currentUserUIFilterList);

问题描述 投票:0回答:1
public class UserUIFilterOutput{
Guid Id
string Name 
string FilterDescription 
 
}

public class UserUIFilter 
{
public int UserId { get; private set; }
public Guid UIFilterId { get; private set; }
public UIFilter UIFilter { get; private set; }
public bool IsVisible { get; private set; }
}

public class UIFilter{
 public string Name { get; set; } 
 public int UIModuleId { get; set; }
 public int FilterTypeId { get; set; } 
 public string FilterDescription  { get; set; } 
}

我的地图像这样并将数据发送到ResolutionContext到currentUserUIGridColumnList


CreateMap<UIGridColumn, UserUIGridColumnOutput>()
.ForMember(destination => destination.UIGridColumnId, map => map.MapFrom(source => source.Id)) 
.ForMember(destination => destination.Order, map => map.MapFrom((source, dest, destMember, resContext) => ((List<UserUIFilter>)resContext.Items["currentUserUIGridColumnList"]).Any(x => x.UIFilterId == source.Id) ?((List<UserUIGridColumn>)resContext.Items["currentUserUIGridColumnList"]).FirstOrDefault(x => x.UIGridColumnId == source.Id).Order: source.DefaultOrderNo)).ForMember(destination => destination.Id, map => map.MapFrom((source, dest, destMember, resContext) => ((List<UserUIFilter>)resContext.Items["currentUserUIGridColumnList"]).Any(x => x.UIFilterId == source.Id) ? ((List<UserUIGridColumn>)resContext.Items["currentUserUIGridColumnList"]).FirstOrDefault(x => x.UIGridColumnId == source.Id).Id : (Guid?)null));    

在我的代码中我像这样使用该地图

List<UserUIGridColumnOutput> returngridColumnList = _mapper.Map<List<UserUIGridColumnOutput>>(gridColumnList, opts => opts.Items["currentUserUIGridColumnList"] = currentUserUIFilterList);

我尝试获取像

(List<UserUIGridColumn>)resContext.Items["currentUserUIGridColumnList"]).FirstOrDefault(x => x.UIGridColumnId == source.Id).Order
这样的direk对象,但不起作用我试图将ResolutionContext提供给List

c# automapper mapper
1个回答
0
投票

您的代码不完整。您必须编写 UIGridColumn 代码结构。

映射实际上用于创建类似的对象以在特殊情况下使用,例如将实体映射到视图模型或将 dto 映射到实体。

请详细解释您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.