0

私は次のクラスを持っています

public class Group 
{
    public int Id { get; set; }
    public string Name { get; set; }

    public virtual ICollection<GroupTier> Tiers { get; set; }
}

public class GroupTier : IEntity
{
    public int Id { get; set; }
    public int GroupId { get; set; }
    public int Tier { get; set; }
    public decimal Amount { get; set; }

    public virtual Group Group { get; set; }
}  

次のViewModelにマップしようとしています

public class GroupViewModel 
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IEnumerable<decimal> Tiers { get; set; }
}  

構成の使用

configuration.CreateMap<Group, GroupViewModel>()
   .ForMember(m => m.Tiers, opt => opt.MapFrom(u => u.Tiers.OrderBy(q => q.Tier).Select(q => q.Amount)));

データベースからのクエリに EF6 を使用しています。Group.Tiersが nullの場合、問題が発生しています。null 値を処理するにはどうすればよいですか?

この構成を使用すると

configuration.CreateMap<Group, GroupViewModel>()
    .ForMember(m => m.Tiers, opt => opt.MapFrom(u => u.Tiers == null ? new List<decimal>() : u.Tiers.OrderBy(q => q.Tier).Select(q => q.Amount)));

このエラーが発生しています

タイプ 'System.Collections.Generic.ICollection' の要素を比較できません

4

0 に答える 0