Let Entity Framework (code first) ignore an indexed property

点点圈 提交于 2019-12-11 00:39:45

问题


In an entity I have following declaration:

Default Property Item(key As String) As String

Because Entity Framework doesn't like indexed properties I've tried to ignore it:

Public Class EntityMap
    Inherits EntityTypeConfiguration(Of EntityMap)
    Public Sub New()
        ' Me.Ignore(Function(x) x.Item()) --- Missing index parameter, compiler error
        ' Me.Ignore(Function(x) x.Item(String.Empty)) --- Gives runtime error
    End Sub
End Class

I've also tried to remove all discovery conventions from modelBuilder so all property relations explicitely must be set:

        modelBuilder.Conventions.Remove(Of AssociationInverseDiscoveryConvention)()
        modelBuilder.Conventions.Remove(Of ComplexTypeDiscoveryConvention)()
        modelBuilder.Conventions.Remove(Of IdKeyDiscoveryConvention)()
        modelBuilder.Conventions.Remove(Of NavigationPropertyNameForeignKeyDiscoveryConvention)()
        modelBuilder.Conventions.Remove(Of PrimaryKeyNameForeignKeyDiscoveryConvention)()
        modelBuilder.Conventions.Remove(Of TypeNameForeignKeyDiscoveryConvention)()

When the linq query to fetch entities is executed the exception "Indexed properties are not supported" is thrown.

Anyone having any idea how to let Entity Framework ignore the indexed property? The property must be public to other entities.

Thanks in advance!

来源:https://stackoverflow.com/questions/6199442/let-entity-framework-code-first-ignore-an-indexed-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!