ExecuteStoreQuery returns multiple rows, how can I get it in IList or List

I have a stored procedure that returns a dynamic request, e, g, if I pass some value to its id parameter, it returns a dynamic request to me, for example

 Select * from someTable tbl where tbl.Id=51 

then I execute this query using ExecuteStoreQuery as

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

container.ExecuteStoreQuery<object>(query); problem container.ExecuteStoreQuery<object>(query); returns a few lines that I want to get to the list, how can I do this

+4
source share
3 answers

create the model of the type you want to return, for example

 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 query ExecuteStoreQuery also return AsQueryable result

  container.ExecuteStoreQuery<mymodel>(query).AsQueryable().ToList(); 
+7
source

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

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

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

+4
source

Stored procedures can be imported into your Entity model. This will result in a function on your ObjectContext that you can call from your code.

When displaying SP, you can let EF display the result of your SP in Entity. If you don’t have a matching object, EF can define the result columns for your stored procedure and display a complex type.

Here is the MSDN documentation that explains this.

+1
source

Source: https://habr.com/ru/post/1393106/


All Articles