2014-10-25 1 views
0

ServiceStack으로 2 개 이상의 테이블을 조인 할 수 있습니까? 나는 그런 일을 시도하지만 난 evrything 연결해야합니다 내가 OrmLite과 SQLite는을 사용하고ServiceStack JOIN 3 개의 테이블

// 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); 

, 감사

답변

4

OrmLite의 Advanced Join Example 쇼에서 당신은 그냥 유지하는 방법을 추가 동일한 쿼리의 예에 조인 :

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); 
:
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 

은 예에서처럼 보일 것이다
+0

예제가 훌륭하게 작동합니다. – Ben