首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ServiceStack连接3个表

ServiceStack连接3个表
EN

Stack Overflow用户
提问于 2014-10-25 17:11:56
回答 1查看 2.2K关注 0票数 2

是否可以使用ServiceStack连接两个以上的表?我尝试过这样的方法,但我需要链接到每件事:

代码语言:javascript
复制
// Join PatientDetails and BedDetails
SqlExpression<PatientDetails.PatientDetails> q = _dbConnection.From<PatientDetails.PatientDetails>();
q.Join<PatientDetails.PatientDetails, BedDetails.BedDetails>((patient, bed) => patient.ByBedId == bed.BedDetailsId);
List<PatientDetails.PatientDetails> PatientBedJOIN = _dbConnection.Select(q);

// Join PatientSession and PatientDetails
SqlExpression<PatientSession> q1 = _dbConnection.From<PatientSession>();
q1.Join<PatientSession, PatientDetails.PatientDetails>((session, patientd) => session.ByPatientId == patientd.PatientDetailsId);
List<PatientSession> SessionPatientJOIN = _dbConnection.Select(q1);

我用的是OrmLite和Sqlite,谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-25 23:57:47

OrmLite的高级连接示例展示了如何继续向同一个查询添加联接,例如:

代码语言:javascript
复制
List<FullCustomerInfo> rows = db.Select<FullCustomerInfo>(  // Map results to FullCustomerInfo POCO
  db.From<Customer>()                                       // Create typed Customer SqlExpression
    .LeftJoin<CustomerAddress>()                            // Implicit left join with base table
    .Join<Customer, Order>((c,o) => c.Id == o.CustomerId)   // Explicit join and condition
    .Where(c => c.Name == "Customer 1")                     // Implicit condition on base table
    .And<Order>(o => o.Cost < 2)                            // Explicit condition on joined Table
    .Or<Customer,Order>((c,o) => c.Name == o.LineItem));    // Explicit condition with joined Tables

在您的示例中,如下所示:

代码语言:javascript
复制
var q = _dbConnection.From<PatientDetails.PatientDetails>()
    .Join<PatientDetails.PatientDetails, BedDetails.BedDetails>(
        (patient, bed) => patient.ByBedId == bed.BedDetailsId)
    .Join<PatientDetails.PatientDetails, PatientSession>(
        (patientd, session) => session.ByPatientId == patientd.PatientDetailsId);

var SessionPatientJOIN = _dbConnection.Select(q);
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26565023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档