Skip to content

Deep nested classes #61

@john-aaron-owens

Description

@john-aaron-owens

Could someone take a look and tell me why Order.OrderDetails is returning as null after the map. The sql works and there is order details in the database. I can get nesting working for the 1 level, but not 2.

btw - I may have a typo as I had to rename the class and fields but the sql does work and no exceptions are being thrown. It just can't find the data which is nested a the 2nd level.

public class Project
{
public long ProjectId { get; set; }
public IEnumerable Orders { get; set; }
}

public class Order
{
public long OrderId { get; set; }
public IEnumerable OrderDetails{ get; set; }
}

public class OrderDetail
{
public long OrderDetailId { get; set; }
}

        var sql = $@"

SELECT
p.Project_ID AS ProjectId
o.Order_ID AS Order_OrderId,
od.Order_Detail_ID AS Order_OrderDetail_OrderDetailId,
FROM
Project AS p
LEFT JOIN Order AS o ON p.Order_ID = o.Order_ID
LEFT JOIN OrderDetail AS od ON o.Order_Detail_ID = od.Order_Detail_ID
";

        Slapper.AutoMapper.Cache.ClearInstanceCache();

        Slapper.AutoMapper.Configuration.AddIdentifiers(typeof(ProjectSampleSetLegacyPortal),
            new List<string> { "ProjectId" });
        Slapper.AutoMapper.Configuration.AddIdentifiers(typeof(StatsLegacyPortal),
            new List<string> { "OrderId" });
        Slapper.AutoMapper.Configuration.AddIdentifiers(typeof(StatsDetailLegacyPortal),
            new List<string> { "OrderDetailId" });

        var results =
            Slapper.AutoMapper.MapDynamic<Project>(query).First();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions