I have a stored procedure that returns a selection of columns from couples of tables.
So I created this class :
public class StoredProcedureResult
{
public int hours_id { get; set; }
public DateTime TimeSheet_Date { get; set; }
public double? Hour_Number { get; set; }
public string Hour_Note { get; set; }
public string Task_Ticket_Libelle { get; set; }
public int Task_Ticket_Id { get; set; }
public int Project_Id { get; set; }
public bool? Is_Task { get; set; }
public int User_Id { get; set; }
public string Project_Name { get; set; }
public string Phase_Name { get; set; }
public string User_Name { get; set; }
public double? Hour_Count_All { get; set; }
public string Client_Name { get; set; }
public string Command_Type { get; set; }
public string Commmand_Etape { get; set; }
public string Code_Affaire { get; set; }
}
the problem is when I called the SqlQuery
method the result's type is not directly converted to StoredProcedureResult
even the returned columns has the same names and types as the class's properties :
var lst = context.Database.SqlQuery<StoredProcedureResult>(builder.ToString()).ToList();
Even I tried this I get the same exception
var lst = context.Database.SqlQuery<object>(builder.ToString()).ToList();
List<StoredProcedureResult> list = new List<StoredProcedureResult>();
foreach (object item in lst)
{
StoredProcedureResult typed = (StoredProcedureResult)item;
list.Add(typed);
}
So I need to know how can I fix this issue?
Aucun commentaire:
Enregistrer un commentaire