c# - How to select varying amount of columns with ExecuteStoreQuery -


i'm dynamically building select query varying number of columns.

select   col0,   b col1,   ...,   c coln ... 

the query supposed retrieve matrix of integers.

when executing query objectcontext.executestorequery, right amount of lines each line seems empty.

here code:

var lines = context.executestorequery<list<int>>(querystring).asenumerable() 

how make work?


i found here should using ado.net kind of things.

unfortunately entity framework 6 not have lot of flexibility in internal mapping code, not able map sql result list<int> or other collection of primitive types.

to understand why not able it, need know internally ef6 uses dbdatareader read sql results, builds columnmap expected generic result type (in case type generic list), , performs dynamic translation of sql results result object using columnmap know column map property of object.

per explanation above, ef6 executestorequery method trying map columns ("a", "b"..etc.) list object properties, , since there no properties on list class match sql result column names not able map it.

these limitations make ado.net 1 of simplest option dynamic columns. can use dbdatareader in following code:

var arr = new list<int>();  using (var md = new context()) {     var conn = md.database.connection;      conn.open();     using (idbcommand cmd = conn.createcommand())     {         cmd.commandtext = "select col1,col2 entities";          using (var reader = (dbdatareader)cmd.executereader())         {             while (reader.read())             {                 (int = 0; < reader.fieldcount; i++)                 {                     arr.add(reader.getint32(i));                 }             }         }     } } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -