我正在建模一个服务业务,在每次访问客户端时执行多项服务。我有一个Visit表,一个Service表和一个链接表,VisitService。我在我的服务中使用此请求DTO来获取访问服务列表:
[Route("/visits/{visitid}/services", Verbs = "GET")]
public class ServicesAtVisit : QueryBase<VisitService, ServiceAtVisit>, IJoin<VisitService, My.Namespace.Service> {
public int VisitId { get; set; }
}
ServiceAtVisit是我投射的自定义DTO。
因为我的一个DTO是一个不幸的名字&#34; Service&#34;,我必须在IJoin中完全限定它,因为否则,它与ServiceStack.Service不明确。现在,当我点击路线时,我收到错误&#34;无法推断VisitService和Service&#34;之间的关系。
有趣的是,我已经使用了其他多对多关系(Client.AssignedStaffMembers,StaffMember.AssignedClients for tables Client - &gt; ClientStaffMember - &gt; StaffMember),我可以&#39看到不同的东西。
问题是我的DTO的名称以及我必须完全符合条件的事实吗?
访问:
[Route("/visits", Verbs = "POST")]
public partial class Visit {
[AutoIncrement]
public long Id { get; set; }
public int ServiceRequestId { get; set; }
public string TimeOfDay { get; set; }
public DateTime Date { get; set; }
public TimeSpan? PreferredStartTime { get; set; }
public TimeSpan? PreferredEndTime { get; set; }
public bool IsFirstVisit { get; set; }
public bool IsLastVisit { get; set; }
public bool IncursWeekendFee { get; set; }
public bool WaiveWeekendFee { get; set; }
public bool IncursHolidayFee { get; set; }
public bool WaiveHolidayFee { get; set; }
public bool IncursLastMinuteSchedulingFee { get; set; }
public bool WaiveLastMinuteSchedulingFee { get; set; }
public bool IncursLastMinuteCancellationFee { get; set; }
public bool WaiveLastMinuteCancellationFee { get; set; }
public int? StaffMemberId { get; set; }
public string Notes { get; set; }
public bool IsCancelled { get; set; }
public DateTime? CheckInDateTime { get; set; }
public int? CheckInStaffMemberId { get; set; }
public DateTime? CheckOutDateTime { get; set; }
public int? CheckOutStaffMemberId { get; set; }
[Ignore]
public ServiceRequest ServiceRequest { get; set; }
[Ignore]
public StaffMember StaffMember { get; set; }
[Ignore]
public List<ServiceAtVisit> ServicesAtVisit { get; set; }
}
VisitService:
public partial class VisitService {
// Workaround for composite key limitation
public string Id {
get {
return this.VisitId.ToString() + "|" + this.ServiceId.ToString();
}
}
public long VisitId { get; set; }
public int ServiceId { get; set; }
public int Quantity { get; set; }
public bool FeeIsWaived { get; set; }
[Ignore]
public Visit Visit { get; set; }
[Ignore]
public Service Service { get; set; }
}
服务:
public partial class Service {
[AutoIncrement]
public int Id { get; set; }
public int ServiceTypeId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int DisplayOrder { get; set; }
public bool IsHourly { get; set; }
public bool IsMonthly { get; set; }
[Ignore]
public ServiceType ServiceType { get; set; }
[Ignore]
public ServicePrice CurrentPrice { get; set; }
}
将结果投影到ServiceAtVisit:
public partial class ServiceAtVisit {
public int ServiceTypeId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int DisplayOrder { get; set; }
public bool IsHourly { get; set; }
public bool IsMonthly { get; set; }
public int VisitId { get; set; }
public int ServiceId { get; set; }
public int Quantity { get; set; }
public bool FeeIsWaived { get; set; }
}
答案 0 :(得分:1)
我刚刚尝试创建一个AutoQuery服务,其中包含您在自定义MyNamespace
下提供的所有类型,并且它按预期工作(在最新的ServiceStack中),即:
服务定义:
namespace MyNamespace
{
[Route("/visits/{VisitId}/services", Verbs = "GET")]
public class ServicesAtVisit : QueryBase<VisitService, ServiceAtVisit>,
IJoin<VisitService, Service>
{
public int VisitId { get; set; }
}
public partial class ServiceAtVisit
{
public int ServiceTypeId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int DisplayOrder { get; set; }
public bool IsHourly { get; set; }
public bool IsMonthly { get; set; }
public int VisitId { get; set; }
public int ServiceId { get; set; }
public int Quantity { get; set; }
public bool FeeIsWaived { get; set; }
}
}
类型定义:
namespace MyNamespace
{
[Route("/visits", Verbs = "POST")]
public partial class Visit
{
[AutoIncrement]
public long Id { get; set; }
public int ServiceRequestId { get; set; }
public string TimeOfDay { get; set; }
public DateTime Date { get; set; }
public TimeSpan? PreferredStartTime { get; set; }
public TimeSpan? PreferredEndTime { get; set; }
public bool IsFirstVisit { get; set; }
public bool IsLastVisit { get; set; }
public bool IncursWeekendFee { get; set; }
public bool WaiveWeekendFee { get; set; }
public bool IncursHolidayFee { get; set; }
public bool WaiveHolidayFee { get; set; }
public bool IncursLastMinuteSchedulingFee { get; set; }
public bool WaiveLastMinuteSchedulingFee { get; set; }
public bool IncursLastMinuteCancellationFee { get; set; }
public bool WaiveLastMinuteCancellationFee { get; set; }
public int? StaffMemberId { get; set; }
public string Notes { get; set; }
public bool IsCancelled { get; set; }
public DateTime? CheckInDateTime { get; set; }
public int? CheckInStaffMemberId { get; set; }
public DateTime? CheckOutDateTime { get; set; }
public int? CheckOutStaffMemberId { get; set; }
//[Ignore]
//public ServiceRequest ServiceRequest { get; set; }
//[Ignore]
//public StaffMember StaffMember { get; set; }
[Ignore]
public List<ServiceAtVisit> ServicesAtVisit { get; set; }
}
public partial class VisitService
{
// Workaround for composite key limitation
public string Id
{
get
{
return this.VisitId.ToString() + "|" + this.ServiceId.ToString();
}
}
public long VisitId { get; set; }
public int ServiceId { get; set; }
public int Quantity { get; set; }
public bool FeeIsWaived { get; set; }
[Ignore]
public Visit Visit { get; set; }
[Ignore]
public Service Service { get; set; }
}
public partial class Service
{
[AutoIncrement]
public int Id { get; set; }
public int ServiceTypeId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int DisplayOrder { get; set; }
public bool IsHourly { get; set; }
public bool IsMonthly { get; set; }
//[Ignore]
//public ServiceType ServiceType { get; set; }
//[Ignore]
//public ServicePrice CurrentPrice { get; set; }
}
}
测试数据:
using (var db = container.Resolve<IDbConnectionFactory>().Open())
{
db.DropAndCreateTable<MyNamespace.Visit>();
db.DropAndCreateTable<MyNamespace.VisitService>();
db.DropAndCreateTable<MyNamespace.Service>();
var visitId = db.Insert(new MyNamespace.Visit {
Date = DateTime.UtcNow, Notes = "Notes"}, selectIdentity: true);
var serviceId = (int)db.Insert(new MyNamespace.Service {
ServiceTypeId = 1, Name = "Name"}, selectIdentity:true);
db.Insert(new MyNamespace.VisitService {
VisitId = visitId, ServiceId = serviceId, Quantity = 1});
}
服务结果:
http://localhost:{port}/visits/1/services.json
JSON响应:
{
offset: 0,
total: 1,
results: [{
serviceTypeId: 1,
name: "Name",
displayOrder: 0,
isHourly: false,
isMonthly: false,
visitId: 1,
serviceId: 1,
quantity: 1,
feeIsWaived: false
}]
}