Single Value from Data Entity - not in entity collection
Example of a single computed value from database, not a declared entity type
private decimal getTuneupAmount(DateTime dateCompleted,int classid, int id)
{
string sql = @"SELECT (count(ow.orderworkid) * (select tuneupamount from mastertable)) as TuneupAmount";
sql += " from tbl_o o ";
sql += " join tbl_work ow on o.orderid=ow.orderid ";
sql += " join _setup s on ow.taskcodenumber=s.TaskCodeNumber and s.typeid =2 ";
sql += " WHERE ow.soldbyid =" + id + " and ow.solddate ='" + dateCompleted+ "' and o.classcodeid=" + classid + " ";
sql += " group by soldbyid,ClassCodeID, ow.solddate";
var tuneamt = (_dbContextZ.Database.SqlQuery(sql).SingleOrDefault());
decimal retval = 0;
if (tuneamt != null)
{
retval = tuneamt.TuneupAmount.HasValue ? (decimal)tuneamt.TuneupAmount.Value:0;
};
return retval;
}
private decimal getTuneupAmount(DateTime dateCompleted,int classid, int id)
{
string sql = @"SELECT (count(ow.orderworkid) * (select tuneupamount from mastertable)) as TuneupAmount";
sql += " from tbl_o o ";
sql += " join tbl_work ow on o.orderid=ow.orderid ";
sql += " join _setup s on ow.taskcodenumber=s.TaskCodeNumber and s.typeid =2 ";
sql += " WHERE ow.soldbyid =" + id + " and ow.solddate ='" + dateCompleted+ "' and o.classcodeid=" + classid + " ";
sql += " group by soldbyid,ClassCodeID, ow.solddate";
var tuneamt = (_dbContextZ.Database.SqlQuery
decimal retval = 0;
if (tuneamt != null)
{
retval = tuneamt.TuneupAmount.HasValue ? (decimal)tuneamt.TuneupAmount.Value:0;
};
return retval;
}
Comments