开发者

Entity Framework: Metadata when Entity Name is Same as Property?

I have a EDM with a entity "Extensions" - within this object is the property extension. I've wired up all the other columns just fine, but this one refuses to wire up. I'm guessing because the entity and the property share the same name? Here is my code, the extensions doesn't work, the prefix does work:

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
        开发者_StackOverflowReturn _prefix
    End Get
    Set(ByVal value As Object)
        _prefix = value
    End Set
End Property

End Class

How can I get this code to work? I've looked all through my data model and it looks like the name should be Extensions!

The error I am receiving is: The associated metadata type for type 'phoneDBentities.Extensions' contains the following unknown properties or fields: extensions. Please make sure that the names of these members match the names of the properties on the main type.


This is a limitation of EF's "convention over configuration" feature.

Here's a related question: Entity Framework Mapping Oddity - member names cannot be the same as their enclosing type

The easiest way to fix the problem would be to rename the property to "PhoneExtension."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜