2017年11月28日 星期二

Entity Framework 無法更新 EntitySet 'customer_payment_type',因為它有 DefiningQuery

當我再改公司一個Ticket時,我更新了一個資料庫的Entity Framework
更新完之後發生了一個錯誤

無法更新 EntitySet 'customer_payment_type',因為它有 DefiningQuery,但是在 <ModificationFunctionMapping> 項目中沒有 <InsertFunction> 項目來支援目前的作業

查了一下Google是資料表沒有索引
所以如果將資料表加上索引重新更新EF就可以解決這一個問題

但是呢這一個資料表在某些原因下無法加入索引
所以該怎麼解決呢
  1. 右鍵點擊edmx文件,選擇Open with,XML編輯器
  2. 在edmx:StorageModels元素中找到實體
  3. 完全刪除DefiningQuery
  4. 重命名store:Schema="dbo"為Schema="dbo"(否則,代碼將生成一個錯誤,說名稱是無效的)
所以簡單說呢就是把edmx打開XML編輯模式


<EntitySet Name="customer_payment_type" EntityType="Self.customer_payment_type"
store:Type="Tables" store:Schema="dbo">
<DefiningQuery>SELECT 
    [customer_payment_type].[customer_id] AS [customer_id], 
    [customer_payment_type].[customer_payment_type_no] AS [customer_payment_type_no], 
    [customer_payment_type].[payment_type] AS [payment_type], 
    [customer_payment_type].[payment_condition] AS [payment_condition], 
    [customer_payment_type].[period_days] AS [period_days], 
    [customer_payment_type].[closed_date] AS [closed_date], 
    [customer_payment_type].[description] AS [description], 
    [customer_payment_type].[remark] AS [remark], 
    [customer_payment_type].[default_value] AS [default_value], 
    [customer_payment_type].[credit_currency] AS [credit_currency], 
    [customer_payment_type].[credit_amount] AS [credit_amount], 
    [customer_payment_type].[createdby] AS [createdby], 
    [customer_payment_type].[createdtime] AS [createdtime], 
    [customer_payment_type].[revisedby] AS [revisedby], 
    [customer_payment_type].[revisedtime] AS [revisedtime], 
    [customer_payment_type].[applyby] AS [applyby], 
    [customer_payment_type].[applytime] AS [applytime], 
    [customer_payment_type].[approvedby] AS [approvedby], 
    [customer_payment_type].[approvedtime] AS [approvedtime], 
    [customer_payment_type].[workflowstate] AS [workflowstate], 
    [customer_payment_type].[workflowstate_remark] AS [workflowstate_remark], 
    [customer_payment_type].[rowstate] AS [rowstate], 
    [customer_payment_type].[update_remark] AS [update_remark], 
    [customer_payment_type].[update_flag] AS [update_flag]
    FROM [dbo].[customer_payment_type] AS [customer_payment_type]
</DefiningQuery>
</EntitySet>
更新成
<EntitySet Name="customer_payment_type" EntityType="Self.customer_payment_type"
Schema="dbo" store:Type="Tables" /> 
收工...

1 則留言: