Search code examples
c#sql-serverservicestackormlite-servicestack

ServiceStack.OrmLite SqlServer new Merge method doesn't work for different names of references


I tried to use the new merge method in ServiceStack.OrmLite Sql Server it works perfectly to load references when the name of the column is the same as the Child Table:

var result = dbCon.SqlList<TimeSheet>("EXEC getAllTimeSheets @timeSheetTypeId, @teamId, @employeeId, @fromDate, @toDate", new { timeSheetTypeId, teamId, employeeId, fromDate, toDate });

// Load the references
var employees = dbCon.Select<Employee>();
var teams = dbCon.Select<Team>();

result.Merge(employees);
result.Merge(teams);

But as you can see below the ApprovedBy property has a child table to Employee table and the merge method is not loading the references for "ApprovedBy" How can I load it?

Employees and Teams are being loaded perfectly, but ApprovedBy (Also Employees table) is not loading in my tests

public class TimeSheet : IHasId<int> 
{
    [Alias("TimeSheetId"), AutoIncrement]
    public int Id { get; set; }

    [Required, References(typeof(Employee))]
    public int EmployeeId { get; set; }
    [Reference]
    public Employee Employee { get; set; }

    public bool? IsApproved { get; set; }

    [References(typeof(Employee))]
    public int? ApprovedById { get; set; }
    [Reference]
    public Employee ApprovedBy { get; set; }

    [References(typeof(Team))]
    public int? TeamId  { get; set; }
    [Reference]
    public Team Team { get; set; }
}

Solution

  • This should now be resolved with this commit which is available from v4.0.41+ that's now available on MyGet.