我有一種情況,我想使用ServiceStack.OrmLite
LoadSelect
來填充由多個表中的列組成的POCO。ServiceStack LoadSelect不正確<Into>參考
基本的背景是有服務請求(要完成一個現場技術)和一個單獨的分配表。對於部分應用程序,我想將ServiceRequest
和ServiceRequestAssignment
合併爲一個ServiceRequestExtended
類。
下面是波蘇斯:
public class ServiceRequest
{
[AutoIncrement]
public int Id { get; set; }
...
}
public class ServiceRequestAssignment
{
[AutoIncrement]
public int Id { get; set; }
[References(typeof(User))]
public int? UserId { get; set; }
[Reference]
public User User { get; set; }
[References(typeof(ServiceRequest))]
public int ServiceRequestId { get; set; }
[Reference]
public ServiceRequest ServiceRequest { get; set; }
public double RelativeOrder { get; set; }
[RowVersion]
public ulong RowVersion { get; set; }
}
// Basically combines all fields of ServiceRequest & ServiceRequestAssignment
public class ServiceRequestExtended : ServiceRequest
{
[References(typeof(User))]
public int? UserId { get; set; }
[Reference]
public User User { get; set; }
public double RelativeOrder { get; set; }
public ulong RowVersion { get; set; }
}
這裏是下述(通用)查詢中使用:
var exp = Db.From<ServiceRequest>()
.Join<ServiceRequestAssignment>()
.Where<ServiceRequest, ServiceRequestAssignment>((q, r) => ...);
var results = Db.LoadSelect<ServiceRequestExtended, ServiceRequest>(exp);
當我做到這一點,即LoadSelect生成查詢到相關聯的表中帶來/ POCO不正確。它在子查詢中引用ServiceRequestExtended
而不是正確的子表(在本例中爲ServiceRequestAssignment
)。
這裏的SQL:
SELECT "Id", "UserName", "TechnicianNumber", "FirstName", "LastName", "PIN", "Active", "Salt"
FROM "Users" WHERE "Id"
IN (SELECT "ServiceRequestExtended"."UserId"
FROM "ServiceRequest"
INNER JOIN "ServiceRequestAssignment"
ON ("ServiceRequest"."Id" = "ServiceRequestAssignment"."ServiceRequestId")
WHERE ...)
所以 - 我到底做錯了什麼? LoadSelect<Into, From>
有錯誤嗎?
我也試過'ServiceRequestExtended.UserId'上的'BelongsTo'屬性沒有成功 – jklemmack