Próbuję uruchomić procedurę w RESTful API NET 5 i Entity Framework Core 5, procedura zwraca dane z różnych tabel.
Problem, z którym mam do czynienia, polega na tym, że nie wiem, jak przeprowadzić procedurę w celu późniejszego powrotu danych w klasie DetailsClientsDto.
Spróbuj wykonać następujące sposoby, ale bezskutecznie:
var result = await _context.Database.SqlQuery<DetailsClientsDto>("EXEC [dbo].[SPROC_DETAILS] @ID_USER", sqlParameters);
var result = await _context.SqlQuery<DetailsClientsDto>("EXEC [dbo].[SPROC_DETAILS] @ID_USER", sqlParameters);
Z powodu błędu:
DataBase facade does not contain a definition for SqlQuery. Is there a using directive missing?
Metoda, którą stosuję, jest następujący:
private readonly MarketContext _context;
public ClientsRepository(MarketContext context) : base(context)
{
_context = context;
}
public async Task<DetailsClientsDto> GetDetailsRepository(SearchDetailsDto details)
{
var sqlParameters = new[]
{
new SqlParameter
{
ParameterName = "ID_USER",
Value = details.IdUser,
SqlDbType = SqlDbType.Int,
},
new SqlParameter
{
ParameterName = "ID_CLIENT",
Value = detalles.IdClient,
SqlDbType = SqlDbType.Int,
IsNullable=true
},
};
return await Task.Run(async () =>
{
var result = await _context.Database.SqlQuery<DetailsClientsDto>("EXEC [dbo].[SPROC_DETAILS] @ID_USER", sqlParameters);
return result;
});
}
public class DetailsClientsDto
{
public int IdUser { get; set; }
public int IdClient { get; set; }
public string User { get; set; }
public string Adress { get; set; }
public string Car { get; set; }
public string Color { get; set; }
}
Proszę, nie możesz mi powiedzieć, jak mam wykonać i przywrócić dane, dziękuję.