2012-08-07 130 views
0

我有一個字符串列表,我需要將其保存到關係實體中。如何在實體框架中保存關係實體

Dim ts = (From t In _repository.GetSettings _ 
       Where t.TrustSettingId = Setting.SettingId).First() 

For i As Integer = 0 To emailAddressList.Count() 
     If(Not emailAddressList(i) = ts.SettingEmailAddresses(i).EmailAddress) 
      ts.SettingEmailAddresses.Add(New SettingHREmailAddress() With {.EmailAddress = emailAddressList(i)}) 
     End If 
    Next 

我收到以下錯誤:

Unable to update the EntitySet 'TrustSettingEmailAddress' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation. 

回答

1

它會告訴你,它不能將數據保存到TrustSettingEmailAddress,因爲它很可能沒有在模型中定義主鍵。如果您嘗試將沒有主鍵的數據庫視圖或表添加到EDMX,則會自動使用DefiningQuery。這也適用於多對多關係中的聯結表。