I'm using Automapper 5.2.0 with EF 6.1.3 in web api project.
public class PushNotification
{
public int[] Stores { get; set; }
}
public class PushNotificationEntity
{
[Key]
public int Id { get; set; }
public ICollection<StoreEntity> Stores { get; set; }
}
public class StoreEntity
{
[Key]
public int Id { get; set; }
public virtual ICollection<PushNotificationEntity> PushNotifications { get; set; }
}
this is mapping,
cfg.CreateMap<PushNotificationEntity, PushNotification>()
.ForMember(dest => dest.Stores,
opts => opts.MapFrom(src => src.Stores.Select(s => s.Id).ToArray()));
this is how I access it,
var item = ctx.PushNotifications.Include(p => p.Stores)
.Where(n => n.Id == id).ProjectTo<PushNotification>(mapperCfg).SingleOrDefault();
I'm getting following error,
System.NotSupportedException.
LINQ to Entities does not recognize the method 'Int32[]
ToArray[Int32](System.Collections.Generic.IEnumerable`1[System.Int32])'
method, and this method cannot be translated into a store expression.