c# - How can I directly execute SQL queries in linq -


in c# vs 2008,i have query ,in query join more 1 tables,so don't know type , want know how directly run sql query in linq .

ienumerable<type> results = db.executequery<type>("sql query") 

my above query works fine want avoid type, want write

var results = db.executequery("sql query"); 

is there way write it?

thanks in advance.

you need specify type map query results. can use system.type object instead of statically specifying generic type parameter:

var results = db.executequery(typeof(customer), "sql query "); 

if want plain ado.net datareader use datacontext.connection property:

using (var cmd = db.connection.createcommand())  {    cmd.commandtext = "sql query ";   var results = cmd.executereader(); } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -