使用上面的LinqToSql实体类并尝试映射到具有相同名称的DTO对象会引发Stackoverflow异常。我已经阅读过,这似乎是与CriteriaGroup对象的Child / Parent关系出现问题。有没有人有任何建议?
用于调用此代码的代码:
var mappedDtos = this.configurationRepository
.GetAll()
.Project()
.To<CriteriaGroupDto>();
GetAll()的位置是:
public override IQueryable<TEntity> GetAll()
{
return this.Table.AsQueryable();
}
我为此制作的映射代码是:
/// <summary>
/// The criteria profile.
/// </summary>
public class CriteriaProfile : Profile
{
/// <summary>
/// The configure.
/// </summary>
protected override void Configure()
{
Mapper.CreateMap<CriteriaGroup, CriteriaGroupDto>()
.ForMember(dest => dest.Groups, opt => opt.MapFrom(src => src.Children))
.ForMember(dest => dest.Parent, opt => opt.MapFrom(src => src.Parent))
.ForMember(dest => dest.Criteria, opt => opt.MapFrom(src => src.CriteriaConfigs));
Mapper.CreateMap<CriteriaConfig, CriteriaConfigDto>()
.Include<RatingConfig, CriteriaConfigDto>()
.Include<CountryConfig, CriteriaConfigDto>()
.Include<TimescaleConfig, CriteriaConfigDto>()
.ForMember(dest => dest.DefaultValue, opt => opt.UseValue(default(object)))
.ForMember(dest => dest.DataType, opt => opt.Ignore())
.ForMember(dest => dest.ElementId, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Options, opt => opt.Ignore());
Mapper.CreateMap<RatingConfig, CriteriaConfigDto>()
.ForMember(dest => dest.JoinOperators, opt => opt.MapFrom(src => src.JoinOperators))
.ForMember(dest => dest.OptionOperators, opt => opt.MapFrom(src => src.Operators));
Mapper.CreateMap<CountryConfig, CriteriaConfigDto>()
.ForMember(dest => dest.JoinOperators, opt => opt.MapFrom(src => src.JoinOperators))
.ForMember(dest => dest.OptionOperators, opt => opt.MapFrom(src => src.Operators));
Mapper.CreateMap<TimescaleConfig, CriteriaConfigDto>()
.ForMember(dest => dest.JoinOperators, opt => opt.MapFrom(src => src.JoinOperators))
.ForMember(dest => dest.OptionOperators, opt => opt.MapFrom(src => src.Operators));
base.Configure();
}
}
因此,未来类别中的其他映射是由于:(EG)
/// <summary>
/// The rating config.
/// </summary>
public partial class RatingConfig
{
/// <summary>
/// Gets the operators.
/// </summary>
public IEnumerable<RatingOperator> Operators
{
get
{
return Enumeration.GetAll<RatingOperator>();
}
}
/// <summary>
/// Gets the join operators.
/// </summary>
public IEnumerable<RuleJoinOperator> JoinOperators
{
get
{
return Enumeration.GetAll<RuleJoinOperator>();
}
}
}