开发者

VB.net - storing values

开发者 https://www.devze.com 2023-01-06 17:03 出处:网络
I\'ve been using the following method to store the primary key value of whatever record is being referenced. I would then call the Content.Id method to retrieve that value for sql commands.

I've been using the following method to store the primary key value of whatever record is being referenced. I would then call the Content.Id method to retrieve that value for sql commands.

My question is - is this good practice? One other told me I should make a session item instead.

This is my ContentDA class

Public Shared Property Id() As Integer
    Get
        Return _ContentId
    End Get
    Set(ByVal value As Integer)
        _ContentId = value
    End Set
End Property

This is Content class

Public Shared Property Id() As Integer
    Get
        Return ContentDA.Id
    E开发者_运维知识库nd Get
    Set(ByVal value As Integer)
        ContentDA.Id = value
    End Set
End Property


I'm not entirely sure what you're asking.

If you're asking, "Is it good practice to reference records by primary key?" then yes. A unique value is necessary when searching through record collections, and primary key is as good as any.

If you're asking, "Is it better to save the commands as global variables and reference them that way?" then no, it's not necessarily better or worse; just different.

Personally, I'd go with the first method, myself.


I see nothing wrong with your general design as far as having a data access class that is directly referenced by the domain/business layer class. However, I was caught off guard by the Shared nature of the declarations of each. It is not typically accepted practice having static/singleton classes used in this manner. Afterall, you can only ever have one Content or ContentDA loaded at any given time in the application domain the way you currently have it set up.

0

精彩评论

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