2011-12-05 40 views
0

中的數據庫調用函數從數據庫生成模型。如何通過EF

在.edmx文件我有一個行字符串

<Function Name="GetUniqueInt" ReturnType="int" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" /> 

其原因是什麼?

回答

2

您需要在某處創建stub method for your function。它應該看起來像:

[EdmFunction("YourModelNamespace", "GetUniqueInt")] 
public static int GetUniqueInt() 
{ 
    throw new NotSupportedException("Direct calls are not supported."); 
} 

將此方法例如放置到您的上下文類並在LINQ查詢中使用它。

+0

我不明白「拋出新的NotSupportedException(」直接調用不支持。「);」不必改變? –

+0

它是存根方法。它應該只在Linq-to-entities查詢中被調用,其中的內容永遠不會被調用,因爲它被轉換爲SQL函數調用。 –