The db you are trying to use on the Service class is an ORM Lite database connection not the Manager.Database that Mike referred you to and the two are not interchangeable.
To use ORM Lite with an adhoc query it looks something like this and uses an anonymous object to pass in the parameter. To use IN_DebtorSpecificPrice a class for this will already exist in Jiwa's JiwaFinancials.Jiwa.JiwaServiceModel namespace, , in other words the class is JiwaFinancials.Jiwa.JiwaServiceModel.IN_DebtorSpecificPrice, ORM Lite uses reflection to match fields from the SQL to class properties.
- Code: Select all
List<Person> results = db.SqlList<Person>("SELECT * FROM Person WHERE Age < @age", new { age=50});
and therefore the code you are trying to create would look like the following for ORM Lite
- Code: Select all
List<JiwaFinancials.Jiwa.JiwaServiceModel.IN_DebtorSpecificPrice> results = db.SqlList<Person>("SELECT * FROM IN_DebtorSpecificPrice WHERE DebtorID= @DebtorID ORDER BY QuantityBreak ASC", new { DebtorID="DEBTOR ID GOES HERE"});
Personally I find the brevity of the ORM Lite code preferable as the other way shown below involves a fair bit more cookie cutter code just to fill an object.
If you are using Jiwa's database on the manager to fill a list it goes something like the below, bear in mind that code below is from inside a class that is a Jiwa collection so Add(img); would where this wasn't the case it becomes result.Add(img); where result might be List<INExtraImage> declared and initialised in the function and then returned instead of the function being void and you won't have some the event handling code like OnRead or properties like Reading.
- Code: Select all
public void ReadRecords(String InvID)
{
string Sql = null;
SqlDataReader SQLReader = null;
bool oldReading = Reading;
try
{
Reading = true;
Clear();
//var db = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database;
var db = this.Manager.Database;
//next line launches the debugger
// //System.Diagnostics.Debugger.Break();
SqlParameter parameter = new SqlParameter("@InventoryID", SqlDbType.Char)
{
Value = InvID
};
Sql =
@"select RecID, InventoryID, Description, Image, LastUpdated, LastUploaded, Deleted, WooCommID from IN_ExtraImages where InventoryID = @InventoryID and deleted = 0 order by Description";
this._inventoryID = InvID;
using (SqlCommand SQLCmd = new SqlCommand(Sql, db.SQLConnection, db.SQLTransaction))
{
SQLCmd.CommandTimeout = this.Manager.Database.DefaultCommandTimeout;
SQLCmd.Parameters.Add(parameter);
SQLReader = SQLCmd.ExecuteReader();
while (SQLReader.Read() == true)
{
INExtraImage img = this.Manager.CollectionItemFactory.CreateCollectionItem<INExtraImage>();
img.RecID = db.Sanitise(SQLReader, "RecID").ToString();
img.InventoryID = db.Sanitise(SQLReader, "InventoryID").ToString();
img.Description = db.Sanitise(SQLReader, "Description").ToString();
img.Image = (byte[])db.Sanitise(SQLReader, "Image");
img.LastUpdated = DateTime.Parse(db.Sanitise(SQLReader, "LastUpdated").ToString());
img.LastUploaded = DateTime.Parse(db.Sanitise(SQLReader, "LastUploaded").ToString());
img.Deleted = bool.Parse(db.Sanitise(SQLReader, "Deleted").ToString());
img.WooCommID = int.Parse(db.Sanitise(SQLReader, "WooCommID").ToString());
Add(img);
}
SQLReader.Close();
}
base.OnRead();
}
finally
{
Reading = oldReading;
if ((SQLReader != null))
{
SQLReader.Close();
}
}
}
By the way if you want Jiwa manager inside a service class you do this but to make it work you need to add the Jiwa Rest Api Plugin as a reference under plugin references if it is not already there.
- Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Manager manager = this.SessionAs<JiwaAuthUserSession>().Manager;
If you want more help with the ORM Lite way see
https://github.com/ServiceStack/ServiceStack.OrmLite, there are also some T4 templates that will help generate code for views, tables and stored procedures.
And one last trick if the name of your plugin would come before that of Jiwa's Rest API plugin, then change the execution order of your plugin to 1 so that Jiwa's Rest API plugin loads first as thing load in order of execution order and then name otherwise you can get some issues.