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));
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.