linq with get a dataset :)


When using LINQ to SQL, it lets you retrieve entity lists as results from SQL queries. While that’s usually what you would like to retrieve from LINQ query, LINQ to SQL also provides an alternative to retrieve a raw IDbCommand statement with the SQL command and all parameters set based on the query expression.

This means that you can actually bypass the Entity list generation and use the query for other purposes like generating a DataReader instead:

var q = from c in db.tt_customers
        where c.Pk > 5
        select c;                        
IDbCommand command = db.GetCommand(q);
command.Connection = Customer.context.Connection;
IDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
this.dgGrid.DataSource = reader;
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s