2017-06-30 69 views
1

我有以下看法:添加視圖到EntityFramework 6不起作用?

SET ANSI_NULLS ON 
GO 

SET QUOTED_IDENTIFIER ON 
GO 



ALTER VIEW [dbo].[RateAverageValueView] WITH SCHEMABINDING 
AS 
    SELECT 
     Id = NEWID(), 
     AverageRateValue = AVG(Value) 
    FROM dbo.Rate 


GO 

但我不能把它添加到EF模型(EDMX文件)。
我知道它應該有一個主鍵列,所以我加了Id = NEWID(),但它不起作用。
什麼問題?

在Visual Studio中的警告一節中列出以下錯誤:
警告:

Error 6013: The table/view 'YoutubeLinks.dbo.RateAverageValueView' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it. 
+0

爲什麼不寫一個標量值函數? –

+0

我只是找到更多經驗問題的原因。 –

+0

什麼不行?請具體說明。你有任何錯誤信息? – Mixxiphoid

回答

0

我改變了以下列:

SET ANSI_NULLS ON 
GO 

SET QUOTED_IDENTIFIER ON 
GO 



ALTER VIEW [dbo].[RateAverageValueView] WITH SCHEMABINDING 
AS 
    SELECT 
     Id = 1, 
     AverageRateValue = AVG(Value) 
    FROM dbo.Rate 


GO 

問題解決了:)

相關問題