I have been reading how to use stored procedures in EF6
But it doesn't show how can i actually get data from a procedure to a model.
For example i have this query
CREATE PROCEDURE Abastecimentos_Select
AS
BEGIN
SELECT * FROM OpenQuery(MACPAC, 'SELECT RD6001 as Referencia, RD6002 as UAP, RD6030 as QTD_AB_PDP_W01 FROM D805DATPOR.TRP060D WHERE RD6001 not like ''%OP%'' and RD6001 not like ''%PT%'' ')
END
I want to populate my model with it, the properties are the tables returned from the procedure
public class Abastecimentos
{
public string Referencia { get; set; }
public string UAP { get; set; }
public float QTD_AB_PDP_W01 { get; set; }
}
I tried using Fluent API but there is no select option
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Abastecimentos>().MapToStoredProcedures(a => a.//No select)
}
I'm using Code First approach.
I decided to use Dapper when mapping SP's to models
public async Task OnGetListAsync() { IDbConnection con = new SqlConnection(_config.GetConnectionString("DefaultConnection"));