I have the following method:
public List<AnfitrionDto> Seleccionar()
{
List<AnfitrionDto> ret = new List<AnfitrionDto>();
VisitantesEntities db = new VisitantesEntities();
Anfitrion[] registros = db.SpAnfitrionConsultar();
foreach (var registro in registros)
{
ret.Add(AnfitrionAdaptador.ConvertirADto(registro));
}
return ret;
}
In which I call an SP with name SpHostConsult, but it shows me the following error:
Is it possible to convert an Object result to an Array in C#? I think that's the problem I'm having.
The types you want to convert seem to be very different, maybe you should use automapper or maybe linq, because regardless of whether it's a
ObjectResult
to an array, the types don't match, you have to map the typeSpAnfitrionConsultar_Result
to thisAnfitrionDto
is where linq comes in.In this case
Select
,linq
you should map the correct properties of each entityI would also recommend you take a look at the article
Call Stored Procedure From Entity Framework
If you review the image of
step 3
you will see that you can indicate the type that returns the execution of the procedureYou should use .ToArray();
Anyway, why don't you use
List<T>
instead of array?Cheers!