EF4 – The selected stored procedure returns no columns

EF doesn’t support importing stored procedures which build result set from:

  • Dynamic queries
  • Temporary tables

The reason is that to import the procedure EF must execute it. Such operation can be dangerous because it can trigger some changes in the database. Because of that EF uses special SQL command before it executes the stored procedure:

SET FMTONLY ON

By executing this command stored procedure will return only “metadata” about columns in its result set and it will not execute its logic. But because the logic wasn’t executed there is no temporary table (or built dynamic query) so metadata contains nothing.

You have two choices (except the one which requires re-writing your stored procedure to not use these features):

  • Define the returned complex type manually (I guess it should work)
  • Use a hack and just for adding the stored procedure put at its beginning SET FMTONLY OFF. This will allow rest of your SP’s code to execute in normal way. Just make sure that your SP doesn’t modify any data because these modifications will be executed during import! After successful import remove that hack.

Leave a Comment