mardi 10 mars 2015

Need help ServiceStack OrmLite how to Update table with Multiple Join table Entity Framework C#

I need the servicestack experts help regarding Servicestack Update query with join multiple tables in C#. I have googled and gone through all the related documents and site but not able to find enough details regarding Update with Join query.


I would like to update the One table with join the three different table and where clause. I have tried all the ways by entity framework but not able to do it. I can do it by Db.ExecuteSql(SqlQuery) but I would like to do it by Entity Framework. My query as below .


I want to update the UpdateStatus of HeartRate Table join with PatientDetails, DeviceSession, PatientSession and HeartRate and where clause id HeartRate.timestamp = ‘@starttime’


SqlQuery =

UPDATE HeartRate SET UpdateStatus = 1

WHERE HeartRateID IN ( SELECT hr.HeartRateID

FROM PatientDetails pd join PatientSession ps on pd.PatientDetailsId = ps.ByPatientId

join DeviceSession ds on ps.PatientSessionId = ds.ByPatientSessionId

join HeartRate hr on ds.DeviceSessionID = hr.ByDevSessionID

WHERE

pd.PatientId = ' @PatientId '

AND hr.Timestamp = ' @starttime' order by hr.Timestamp Asc )


I need something like below (Its wrong and incomplete).


Db.UpdateOnly(new HeartRate { UpdateStatus = 1 }, ps => new { ps.UpdateStatus },

.SqlJoinBuilder<DeviceSession, PatientSession>((ds2, ps) => ds2.ByPatientSessionId == ps.PatientSessionId) .Join<PatientSession, PatientDetails>((ps2, pd) => ps2.ByPatientId == pd.PatientDetailsId) .Where<HeartRate, PatientDetails>((lthr2, pd2) => (lthr2.Timestamp == @starttime) && pd2.PatientId == PatientId).OrderBy(lthr2 => lthr2.Timestamp));


Please help me out.


Thanks


Susheel


Aucun commentaire:

Enregistrer un commentaire