For executing SQL Queries that will return results form an known entity, you could use the DataContext.ExecuteQuery method:
IEnumerable<Post> = dataContext.ExecuteQuery<Post>(sqlQuery);
For custom results sets, the Execute method cannot infer and create the anonymous type, but you still can create a class, that contains the fields which are selected in your custom SQL query.
class CustomPostResult // custom type for the results
{
public int? PostId { get; set; }
public DateTime PostedDateUtcTime { get; set; }
}
//...
string sqlQuery = @"SELECT DISTINCT TOP 1 'PostId' = ISNULL(RootPost,Id),
PostedDateTimeUtc FROM Post ORDER BY PostedDateTimeUtc DESC";
IEnumerable<CustomPostResult> = dataContext.
ExecuteQuery<CustomPostResult>(sqlQuery);
Check this article: