Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExecuteStoreQuery return multiple rows how can i get it into an IList or List

I have a stored procedure that returns a dynamic query, e,g if i pass some value to its id parameter it return me a dynamic query like

Select * from someTable tbl where tbl.Id=51

then i execute this query using ExecuteStoreQuery like

string query = container.CreateQuery<string>(
                    "SELECT VALUE DB.Store.GetQuery(@ID) FROM {1}",
                    new System.Data.Objects.ObjectParameter("ID", 51)
                ).First();

object lists = container.ExecuteStoreQuery<object>(query);

the problem is container.ExecuteStoreQuery<object>(query); returns multiple rows which i want to get into a list, how can i do that

like image 617
John x Avatar asked Dec 17 '22 04:12

John x


2 Answers

create a model of type you want to return the results like

public class mymodel{

public int _key{get;set;}
public string _value{get;set;}
}

where _key and _value correspond to the columns of the returned result

execute the query ExecuteStoreQuery also return the result AsQueryable

 container.ExecuteStoreQuery<mymodel>(query).AsQueryable().ToList();
like image 144
Rafay Avatar answered May 14 '23 06:05

Rafay


I'm not sure if I understand your question but it looks like you are looking for ToList method:

List<MyEntity> list = container.ExecuteStoreQuery<MyEntity>(query).ToList();

The bigger problems is object in your code - if you really mean object type it will not work. You must provide a real type (either mapped entity, complex type or custom class with public properties using same names as columns in result set) otherwise EF will not fill data for you.

like image 41
Ladislav Mrnka Avatar answered May 14 '23 07:05

Ladislav Mrnka