实体框架:实体名称与属性相同时的元数据?

时间:2010-06-30 17:23:40

标签: asp.net entity-framework ado.net entity-framework-4

我有一个带有实体“扩展”的EDM - 在此对象中是属性扩展。我已经将所有其他列连接好了,但是这个列拒绝连接。我猜是因为实体和属性共用同一个名字? 这是我的代码,扩展不起作用,前缀确实有效:

Imports System.Web.DynamicData
Imports System.ComponentModel.DataAnnotations
<MetadataType(GetType(ExtensionsMetaData))> _
Partial Public Class Extensions

End Class
Public Class ExtensionsMetaData
Private _phones_extensions As Object
Private _prefix As Object
Private _did_flag As Object
Private _len As Object
Private _sfc_id As Object
Private _name_display As Object
Private _floor As Object
Private _room As Object
Private _phones_departments As Object
Private _phones_buildings As Object
Private _phones_phones As Object
Private _phones_restriction_classes As Object
Private _phones_tens As Object
<DisplayName("Extension")> _
Public Property extensions() As Object
    Get
        Return _phones_extensions
    End Get
    Set(ByVal value As Object)
        _phones_extensions = value
    End Set
End Property
<DisplayName("Prefix")> _
Public Property prefix As Object
    Get
        Return _prefix
    End Get
    Set(ByVal value As Object)
        _prefix = value
    End Set
End Property

结束班

如何让此代码生效?我查看了整个数据模型,看起来名称应该是Extensions!

我收到的错误是:'phoneDBentities.Extensions'类型的关联元数据类型包含以下未知属性或字段:extensions。请确保这些成员的名称与主要类型的属性名称相匹配。

1 个答案:

答案 0 :(得分:2)

这是EF的“约定优于配置”功能的限制。

以下是相关问题:Entity Framework Mapping Oddity - member names cannot be the same as their enclosing type

解决问题的最简单方法是将属性重命名为“PhoneExtension。”