开发者

Virtual property with private set

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 i开发者_StackOverflown advance...


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


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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜