如何在实体框架中保存关系实体

时间:2012-08-07 11:57:42

标签: vb.net entity-framework-4.1

我有一个字符串列表,我需要保存到关系实体。

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 个答案:

答案 0 :(得分:1)

它告诉您它无法将数据保存到TrustSettingEmailAddress,因为它很可能没有在您的模型中定义主键。如果您尝试将没有主键的数据库视图或表添加到EDMX,则会自动使用DefiningQuery。对于多对多关系中的联结表,也会发生这种情况。

相关问题