当前位置:编程学习 > asp >>

ASP.NET:自定义实体类

ASP.NET:自定义实体类
 
什么是自定义实体?

自定义实体是代表业务域的对象,因此,它们是业务层的基础。如果您有一个用户身份验证功能(本文通篇都使用该示例进行讲解),您就可能具有 User 和 Role 对象。电子商务系统可能具有 Supplier 和 Merchandise 对象,而房地产公司则可能具有 House、Room 和 Address 对象。在您的代码中,自定义实体只是一些类(实体和“类”之间具有非常密切的关系,就像在 OO 编程中使用的那样)。一个典型的 User 类可能如下所示:


[vb]
'Visual Basic .NET  
声明User信息表类 
Public Class UserE 
 
#Region "Fields and Properties"  
定义表中各种信息 
    Private _UserID As String 
  
Private _PWD As String 
  
Private _Level As String 
  
Private _UserName As String 
  
    Private _Head As String 
 
 
    '对User表中字段UserID的存取  
    Public Property UserID() As String 
        Get 
            Return _UserID 
  
        End Get 
        Set(value As String) 
            _UserID = value 
  
        End Set 
    End Property 
  
    '对user表中字段密码的存取  
    Public Property PWD() As String 
        Get 
            Return _PWD 
  
        End Get 
        Set(value As String) 
  
            _PWD = value 
  
        End Set 
    End Property 
  
    '对User表中字段Level的存取  
    Public Property Level() As String 
        Get 
            Return _Level 
  
        End Get 
        Set(value As String) 
            _Level = value 
  
        End Set 
    End Property 
    '对user表中字段UserName的存取  
  
    Public Property UserName() As String 
        Get 
            Return _UserName 
  
        End Get 
        Set(value As String) 
            _UserName = value 
  
        End Set 
    End Property 
   
    '对User表中字段Head的存取  
    Public Property Head() As String 
        Get 
            Return _Head 
  
        End Get 
        Set(value As String) 
            _Level = value 
  
        End Set 
    End Property 
  
  
End Class 
  

'Visual Basic .NET
声明User信息表类
Public Class UserE

#Region "Fields and Properties"
定义表中各种信息
    Private _UserID As String
 
Private _PWD As String
 
Private _Level As String
 
Private _UserName As String
 
    Private _Head As String


    '对User表中字段UserID的存取
    Public Property UserID() As String
        Get
            Return _UserID
 
        End Get
        Set(value As String)
            _UserID = value
 
        End Set
    End Property
 
    '对user表中字段密码的存取
    Public Property PWD() As String
        Get
            Return _PWD
 
        End Get
        Set(value As String)
 
            _PWD = value
 
        End Set
    End Property
 
    '对User表中字段Level的存取
    Public Property Level() As String
        Get
            Return _Level
 
        End Get
        Set(value As String)
            _Level = value
 
        End Set
    End Property
    '对user表中字段UserName的存取
 
    Public Property UserName() As String
        Get
            Return _UserName
 
        End Get
        Set(value As String)
            _UserName = value
 
        End Set
    End Property
 
    '对User表中字段Head的存取
    Public Property Head() As String
        Get
            Return _Head
 
        End Get
        Set(value As String)
            _Level = value
 
        End Set
    End Property
 
 
End Class
&n

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,