As I found in the thread below, you can use the DataContext.GetCommand(IQueryable)
to get a DbCommand
for the query you wish to execute. You can add "OPTION (RECOMPILE)" to the command text, from that, open a reader, and use [DataContext.Translate<T>
]1 to translate the opened reader to the entity type you wanted.
http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/def80609-eaf2-4631-8d3d-ad10fc9aedfa
For example, given a DataContext dataContext
:
IQueryable<string> exampleItemsQuery = dataContext.Table.Where(…).Select(…); //etc
DbCommand command = dataContext.GetCommand(exampleItemsQuery);
command.CommandText += Environment.NewLine + "OPTION (RECOMPILE)";
if (dataContext.Connection.State != ConnectionState.Open)
dataContext.Connection.Open();
IEnumerable<string> exampleItems = dataContext.Translate<string>(command.ExecuteReader(CommandBehavior.CloseConnection));