Starts in:
1 DAY
23 HRS
51 MIN
50 SEC
Starts in:
1 D
23 H
51 M
50 S
Open Closed

Not Getting Custom Mapping #1212


User avatar
0
RonaldR created
  • ABP Framework version: v4.2
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:
  • I have a data class and a model class. i sem calling createMap in the Profile class to set up my mapping. the problem i am having is there is a foreign key to another table and a member of the type for that table. when the data gets to the fron end the site data object is not in there. i added a SiteName field, which is the data i need on the UI. i altered the CreateMap by adding a ForMembet call. still not getting the name in the mapped data. here are the two modeks and the mapping:
public class SubnetDataModel : AuditedAggregateRoot<Guid>, IMultiTenant
{
    public Guid? TenantId { get; set; }
    public string Network { get; set; }
    public string MaskBit { get; set; }
    public string StartRange { get; set; }
    public string EndRange { get; set; }
    //public string Category { get; set; }
    public SiteDataModel SiteData { get; set; }
    [ForeignKey("SiteData")]
    public Guid? SiteId { get;  set; }
}

 public class SubnetModel : AuditedEntityDto<Guid>
{
    public string Network { get; set; }
    public string MaskBit { get; set; }
    public string StartRange { get; set; }
    public string EndRange { get; set; }
    //public SiteModel SiteData { get; set; }
    public Guid? SiteId { get; set; }
    public string SiteName { get; set; }
}

CreateMap<SubnetDataModel, SubnetModel>().ForMember(x => x.SiteName, y => y.MapFrom(src => src.SiteData.Name));

1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    HI

    You should load the SiteData navigation property when querying the SubnetDataModel. Then the Automapper will works.

    https://docs.abp.io/en/abp/latest/Entity-Framework-Core#eager-loading-load-with-details

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06