jeudi 15 janvier 2015

I need the help in C# ORMLite servicestack webservice using SQLite database. In which I am sending the one string field 'Code' and getting the matched data from two tables.


I am facing the error in SQL Expression under Db.SqlList("Sql Query").


Actually I am expecting multiple records in Response in a List as return value.


Please help me out how the fill the List as return from SQLExpression under ServiceStack webservice. I do not want to use entity framework for SQl queries.


Database Table


Table 1 { int ID, string Field1 }


Table 2 { int ID, int LinkId , string Field2, string code }


Sample Code



[Route("/CodeStatus/{Code}", Verbs = "GET")]
public class CodeStatus : IReturn<ServiceResponse>
{
//public int DeviceStatusID { get; set; }

public string Code { get; set; }
}


// Service Response


public class ServiceResponse { public string Field1 { get; set; } public string Field2 { get; set; } }



public class CodeStatusService : Service
{

CrudFunctions<CodeStatus> _crud;

public object ANY(CodeStatus request)
{
return Crud.AskForStatus(request.ConvertTo<CodeStatus>());
}


}


public class CrudFunctions {



public IDbConnection Db { get; private set; }

public CrudFunctions(IDbConnection db)
{
Db = db;
}

// Check the multiple data as per 'Code' in Table 2

public object AskForStatus(PatientStatus request)
{
List<ServiceResponse> strList = Db.SqlList<ServiceResponse>("SELECT PD.Field1 As Field1, BD.Field2 AS Field2 lsId FROM Table1 T1 JOIN Table2 T2 ON T1.Id = T2.LinkId WHERE T2.Code = " + request.Code);
}


}


Aucun commentaire:

Enregistrer un commentaire