ServiceStack LoadSelect 未正确 <Into> 引用
ServiceStack LoadSelect not properly <Into> references
我有一个案例,我想使用 ServiceStack.OrmLite
LoadSelect
来填充由多个 table 的列组成的 POCO。
基本背景是有服务请求(需要现场技术人员完成)和单独的任务 table。对于应用程序的一部分,我想将 ServiceRequest
和 ServiceRequestAssignment
组合成一个 ServiceRequestExtended
class。
这是 POCO:
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 生成的用于引入关联的 tables / POCO 的查询是不正确的。它在子选择中引用 ServiceRequestExtended
而不是正确的子项 table(在本例中为 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>
中有错误吗?
OrmLite Self References 只能在 real 表上,因为 OrmLite 需要查询现有的引用字段 ID 来填充 POCO 引用。
我有一个案例,我想使用 ServiceStack.OrmLite
LoadSelect
来填充由多个 table 的列组成的 POCO。
基本背景是有服务请求(需要现场技术人员完成)和单独的任务 table。对于应用程序的一部分,我想将 ServiceRequest
和 ServiceRequestAssignment
组合成一个 ServiceRequestExtended
class。
这是 POCO:
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 生成的用于引入关联的 tables / POCO 的查询是不正确的。它在子选择中引用 ServiceRequestExtended
而不是正确的子项 table(在本例中为 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>
中有错误吗?
OrmLite Self References 只能在 real 表上,因为 OrmLite 需要查询现有的引用字段 ID 来填充 POCO 引用。