使用Automapper MapFrom获取带有WHERE筛选的Count()

使用Automapper MapFrom获取带有WHERE筛选的Count(),automapper,Automapper,鉴于该实体: public class Album { public string Name { get; set; } public string Artist { get; set; } public virtual AlbumCollections AlbumCollections { get; set; } } 连同这个DTO public class AlbumDto { public string Name { get; set; } public string Artist {

鉴于该实体:

public class Album
{
public string Name { get; set; }
public string Artist { get; set; }
public virtual AlbumCollections AlbumCollections { get; set; }
}
连同这个DTO

public class AlbumDto
{
public string Name { get; set; }
public string Artist { get; set; }
public int AlbumCount { get; set; }
}
如何返回姓名和艺术家匹配的相册计数(即重复相册计数)

我的第一次尝试:

Mapper.CreateMap<Album, AlbumDto>()
                .ForMember(dest => dest.AlbumCount, opt => opt.MapFrom(so => so.AlbumCollections.Album.Where(x => x.Name == x.Name && x.Artist == x.Artist).Count()) );

前两项的计数应为“2”,最后一项的计数应为“1”。如何正确设置WHERE过滤器?

您可能应该使用自定义解析器来计算计数。请参见此处的示例->这是我的WHERE子句。。。应该在哪里(x=>x.Name==so.Name&&x.Artist==so.Artist.Count())
{
name: "My Album",
artist: "My Artist",
albumCount: "3"
},
{
name: "My Album",
artist: "My Artist",
albumCount: "3"
},
{
name: "My Different Album",
artist: "My Different Artist",
albumCount: "3"
}