我尝试在ServiceStack.OrmLite Sql Server中使用新的合并方法,当列的名称与子表相同时,它可以很好地加载引用:
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);
但是正如您在下面看到的那样,ApprovedBy属性有一个子表到Employee表,并且merge方法没有加载“ApprovedBy”的引用如何加载它?
员工和团队正在被完美加载,但ApprovedBy(也是 员工表)未在我的测试中加载
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; }
}