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

发布于 2024-09-07 16:10:12 字数 1296 浏览 3 评论 0原文

我有一个带有实体“扩展”的 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

End Class

我怎样才能让这个代码工作?我已经查看了我的数据模型,看起来名称应该是扩展!

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

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
        Return _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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少心凉 2024-09-14 16:10:12

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

这是一个相关的问题: Entity框架映射奇怪 - 成员名称不能与其封闭类型相同

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

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."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文