2013-09-27 47 views
0

我們必須將使用EF5的項目降級到EF4,並爭取將存儲過程存入EF模型。EF4.4中的存儲過程

程序返回一個表:

-- A table to hold the results 
    DECLARE @Result TABLE 
    (
     ActionType CHAR(1), 
     ChangedBy  VARCHAR(50), 
     ChangedDate DATETIME, 
     FieldName  VARCHAR(150), 
     OriginalValue VARCHAR(100), 
     NewValue VARCHAR(100), 
     ForeignKeyName VARCHAR(50), 
     ForeignKeyValue VARCHAR(15) 
) 

,然後添加記錄,並返回:

-- Return the result 
    SELECT * FROM @Result 

然而,增加一個進程似乎很不同。存儲過程沒有出現在我們的實體框架上下文中。

所以我們遵循此處所示的例子: http://msdn.microsoft.com/en-us/library/bb896231.aspx

然而,我們選擇返回類型爲「複雜的」,但是,當我們點擊「獲取列信息」,我們用下面的錯誤招呼:

An exception of type 「Microsoft.SqlServer.Management.Sdk.Sfc.EnumeratorException」 occurred while attempting to get columns information. The exception message is: ExecuteScalar requires an open and available Connection. The connection’s current state is closed. The inner exception caught was of type ‘System.InvalidOperationException’, with this error message: ‘ExecuteScalar requires an open and available Connection. The connection’s current state is closed.’.

任何人都可以幫助這個錯誤,或者可能解釋一個更好的方法來引用存儲過程在EF4.4?

回答

1

解決!不要使用SELECT *!

-- Return the result 
    SELECT  
     ActionType, 
     ChangedBy, 
     ChangedDate, 
     FieldName, 
     OriginalValue, 
     NewValue, 
     ForeignKeyName, 
     ForeignKeyValue 
    FROM @Result 
+1

+1 *不使用'SELECT *'* ** **總是**生產系統中的好建議! –

+0

確實。我違反了規則。但希望我的錯誤會幫助別人。 – Craig