Vykonanie postupu a vrátiť sa údaje z rôznych tabuliek v Net 5

0

Otázka

Snažím spustiť postup Pokojný API s NETTO 5 a Entity Framework Core 5, postup, vráti údaje z rôznych tabuliek.

Problém mám, je, že neviem, ako chcete vykonať postup na neskôr vrátiť údajov, v DetailsClientsDto triedy.

Skúste spustiť postup v nasledujúcich spôsobov, bez úspechu:

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);

Chyby:

DataBase facade does not contain a definition for SqlQuery. Is there a using directive missing?

Metóda som pomocou je:

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; }
}

Prosím, môžete mi povedať, ako by som mal vykonanie postupu a vrátiť údaje, ďakujem.

1

Najlepšiu odpoveď

0

Toto je príklad:

// Load this namespace to use SqlParameter
using Microsoft.Data.SqlClient;

//.. or use db.Set<DetailsClientsDto>()
var result = await db.DetailsClientsDto 
  .FromSqlRaw("EXEC [dbo].[SPROC_DETAILS] @idUser, @anotherParam", 
    new SqlParameter("idUser", value1),     
    new SqlParameter("anotherParam", value2))
  .AsNoTracking()
  .ToListAsync()
2021-11-24 01:46:45

V iných jazykoch

Táto stránka je v iných jazykoch

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................