虚拟财产与私人集

发布于 2024-08-19 19:55:27 字数 383 浏览 4 评论 0原文

我正在尝试在 MVC 项目中使用 Fluent nhibernate...我对 nhibernate 和 Fluent 非常陌生...似乎实体应该具有虚拟的属性,并且该集合对于 ID 应该是私有的...我使用 vb 语言...所以尝试使用可重写...它给出了一个错误...

Public Overridable Property DesignId() As Integer
    Get

    End Get
    Private Set(ByVal value As Integer)

    End Set
End Property

它说属性不能被重写,因为它有一个私有访问器...不知道如何进行...网上的所有教程都是c# ...我的客户特别是VB...提前致谢...

I am trying to use fluent nhibernate in a MVC project... i am very new to nhibernate and fluent... It seems the entities should have properties that are virtual and the set should be private for IDs... i use vb language...so tried using overrideable...it gives an error...

Public Overridable Property DesignId() As Integer
    Get

    End Get
    Private Set(ByVal value As Integer)

    End Set
End Property

it says property cannot be overrideable because it has a private accessor...have no idea how to go about...all tutorials in the net are in c#... my client specifically in vb....thanks in advance...

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

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

发布评论

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

评论(3

泛泛之交 2024-08-26 19:55:28

特别是对于 VB,如果您将 setter 设置为受保护,则应该避免出现错误(因为受保护允许您覆盖该设置)。

Specifically to VB, if you make the setter protected, that should avoid giving you the error (since Protected allows you to override the setting).

千纸鹤带着心事 2024-08-26 19:55:28

使用受保护的而不是私有的。如果您的设计可以的话,使用 Public 也可以 - Set 不必是 Private,这就是好的设计。

私有错误是 VB 限制,这在 C# 中有效。 VB 需要重写 getter 和 setter,而 C# 则不需要。

Use Protected instead of Private. It's OK to use Public, too, if that OK with your design - Set is not necessary to be Private, that's just good design.

The Private error is VB limitation, this works in C#. VB requires to override both getter and setter, while C# does not.

皓月长歌 2024-08-26 19:55:27

如何使 setter 受到保护,以便重写的类可以看到它......

即:

Private _designId as Integer
Public Overridable Property DesignId() As Integer
    Get
        Return _designId
    End Get
    Protected Set(ByVal value As Integer)
        _designId = value
    End Set
End Property

How about making the setter protected, so that the overriding classes can see it...

I.e.:

Private _designId as Integer
Public Overridable Property DesignId() As Integer
    Get
        Return _designId
    End Get
    Protected Set(ByVal value As Integer)
        _designId = value
    End Set
End Property
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文