Is it possible to make LinQ to SQL read and understand a pure SQL query such as the following?
SELECT * from myTable
My boss asked me to write directly to database the pure SQL querys in a certain table and this table will have a field named “typeOfSelect”, for example.
And, in my application, I will have to read this field “typeOfSelect” and make LinQ understands what that means.
Thanks!
You can use the ExecuteCommand and ExecuteQuery methods on the DataContext.
ExecuteQuery will work with any object that has property names that match the column names of the table. ExecuteCommand is used for SQL commands that don’t return a result set.
Another way would be to use the Connection.CreateCommand() method on a DataContext which will return a DbCommand object. Then you simply set the CommandText property with the SQL you want to execute.
You can also look at this MSDN link for some other examples.