Assign Cursor to List

0

How can I assign the results of a cursor to a List using SQL Server and Visual Studio ?

The cursor is in a stored procedure, which must be called from the Controller:

Stored Procedure

CREATE PROCEDURE Lista_municipios
@MunicipiosCursor CURSOR VARYING OUTPUT
AS
SET NOCOUNT ON;
SET @MunicipiosCursor = CURSOR
FORWARD_ONLY STATIC FOR
select m.id_municipio,
       m.ca_municipio
  from Municipio m
OPEN @MunicipiosCursor;

Controller

private InvestigacionEntities db = new InvestigacionEntities();

// GET api/Municipios
public IEnumerable<Municipio> GetMunicipios()
{
   //var test = db.Lista_municipios;
   return db.Lista_municipios.AsEnumerable();
}
    
asked by Gdaimon 13.09.2016 в 07:16
source

1 answer

0

No cursor is required for a simple SELECT , it's not necessary, it would simply be:

CREATE PROCEDURE Lista_municipios
AS
SET NOCOUNT ON;

select m.id_municipio,
       m.ca_municipio
  from Municipio m

I do not know how you are mapping, with Entity Framework if you use Code First or% edmx

Stored Procedure in Entity Framework

In the article it raises just what I mention of Procedure

    
answered by 13.09.2016 в 08:57