I'm attempting to execute a SQL Server stored procedure that takes two parameters and returns a list of results. The application is returning the results however I'm unsure how to assign the values to the list in the model. The ORM being utilized is Dapper. Here's my code
string startTime = "2018-04-17 00:00:00.000";
string endTime = "2018-04-17 23:59:59.997";
string db = "database";
List<ShelfInventoryModel> output = new List<ShelfInventoryModel>();
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(SqlConnection.CnnString(db)))
{
DataTable dt = new DataTable();
var p = new DynamicParameters();
p.Add("@StartDate", startTime);
p.Add("@EndDate", endTime);
output = connection.Query<ShelfInventoryModel>("dbo.spGetInventory_Liquor", p, commandType: CommandType.StoredProcedure).ToList();
Console.WriteLine(output);
Console.ReadLine();
}
This is the model class
public class ShelfInventoryModel
{
public decimal Quantity { get; set; }
public string ItemName { get; set; }
}
I understand that the results need to be filled into potentially a data adapter. However the system gives me an error when I attempt to fill the output to the data adapter
The purpose to return the results to the console. However, at this time the console is only showing:
System.Collections.Generic.List`1[ProcedureTest.ShelfInventoryModel]
outputa newListif you're going to replace it with whateverQuery<...>(...).ToList()returns.outputshould contain a list ofShelfInventoryModelobjects. Can't see anything wrong with that code. So I'm really not sure what you're trying to ask here.outputshould contain a list ofShelfInventoryModelobjects, one for each row returned by the stored procedure, with the value from columnsQuantityandItemNameput into those objects. (No need for a data adapter.) So what exactly is the problem?