I'm trying to get the result of the query into a custom model that I created but I get an error:
Cannot create a DbSet for 'POEntry' because this type is not included in the model for the context.
That's because POEntry
is a custom model to get the data from the query.
I also tried to use FromSqlInterpolated
and I get the same error
public async Task<List<POEntry>> GetClosedTransferInsEntries()
{
var TRInsClosed = @" SELECT e.ID as ID,e.PurchaseOrderID as OID,e.ItemID as ItemID,e.ItemDescription as ItemDescription,i.Quantity as QuantityOnHand, " +
" (case when po.Remarks like 'COR%' then 'COR' else '' end) as COR," +
" e.QuantityOrdered,sl.MasterPackQuantity as MasterPackQuantity," +
" i.ItemLookupCode as ItemLookupCode,e.QuantityReceivedToDate as QuantityReceived," +
" 1 as ReasonID," +
" (case when po.ConfirmingTo = 'Done' then CAST(1 AS BIT) when po.ConfirmingTo = '' then CAST(0 AS BIT) end) as IsSyncHQ," +
" (case when i.ItemType = 6 then CAST(1 AS BIT) when ((i.ItemType = 0 or i.ItemType = 3) and i.ItemLookupCode like '20%') then CAST(1 AS BIT) else CAST(0 AS BIT) end ) as Weight," +
" (case when (i.DepartmentID = 289 or i.DepartmentID = 258) then CAST(0 AS BIT) else CAST(1 AS BIT) end ) as HasDate, " +
" i.SupplierID as SupplierID, (case when (select Sum(Quantity) from HH_Production where ItemID = e.ItemID group by ItemID) is null then 0 else (select Sum(Quantity) from HH_Production where ItemID = e.ItemID group by ItemID) end) as TotalQuantity ,(case when aa.Alias is null then '' else aa.Alias end )as Alias, (case when IsNull(CONVERT(datetime, hp.ExpireDate),'')='' then ' ' else Convert(varchar(50), hp.ExpireDate,101) end) as ExpireDate ," +
" (case when IsNull(CONVERT(datetime, hp.ProductionDate),'')='' then ' ' else Convert(varchar(50), hp.ProductionDate,101) end) as ProductionDate " +
" FROM PurchaseOrderEntry AS e Inner JOIN PurchaseOrder AS po ON e.PurchaseOrderID = po.ID Inner JOIN Item AS i ON e.ItemID = i.ID" +
" Left JOIN Alias as aa ON e.ItemID = aa.ItemID Left JOIN HH_Production as hp ON po.ID = hp.PurchaseOrderID and hp.ItemID = e.ItemID Inner JOIN SupplierList as sl ON e.ItemID=sl.ItemID " +
" WHERE(po.POType = 2 or po.POType = 4) AND(po.Status = 2) and po.SupplierID = 0 And (po.DateCreated > DATEADD(DAY, -10, GETDATE())) order by po.DateCreated ";
var mm = db.Set<POEntry>().FromSqlRaw(TRInsClosed).ToList();
return mm;
}
i have the sql query in a string and i want to execute it and get the result in a model that i created to receive the data selected from the query