⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _categories.vb

📁 EasyObjects 是ORM的典型应用的例子是学习研究的很好的范例
💻 VB
📖 第 1 页 / 共 2 页
字号:
'===============================================================================
'  Generated From - VbNet_EasyObject_BusinessEntity.vbgen
' 
'  ** IMPORTANT  ** 
'  
'  This object is 'MustInherit' which means you need to inherit from it to be able
'  to instantiate it.  This is very easily done. You can override properties and
'  methods in your derived class, this allows you to regenerate this class at any
'  time and not worry about overwriting custom code. 
'
'  NEVER EDIT THIS FILE.
'
'  Public Class YourObject 
'      Inherits _YourObject
'
'  End Class
'
'===============================================================================

' Generated by MyGeneration Version # (1.2.0.2)

Imports System
Imports System.Data
Imports System.Data.Common
Imports System.Configuration
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Xml
Imports System.IO

Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports NCI.EasyObjects


#Region " Schema "

Public Class CategoriesSchema
	Inherits NCI.EasyObjects.Schema

    Private Shared _entries As ArrayList
	Public Shared CategoryID As New SchemaItem("CategoryID", DbType.Int32, True, False, False, True, True, False)
	Public Shared CategoryName As New SchemaItem("CategoryName", DbType.String, SchemaItemJustify.None, 15, False, False, False, False)
	Public Shared Description As New SchemaItem("Description", DbType.String, SchemaItemJustify.None, 1073741823, True, False, False, False)
	Public Shared Picture As New SchemaItem("Picture", DbType.Binary, False, True, False, False, False, False)

    Public Overrides ReadOnly Property SchemaEntries() As ArrayList
        Get
            If _entries Is Nothing Then
                _entries = New ArrayList()
				_entries.Add(CategoriesSchema.CategoryID)
				_entries.Add(CategoriesSchema.CategoryName)
				_entries.Add(CategoriesSchema.Description)
				_entries.Add(CategoriesSchema.Picture)
			End If
            Return _entries
        End Get
    End Property

	Public Shared ReadOnly Property HasAutoKey() As Boolean
        Get
            Return True
        End Get
    End Property

    Public Shared ReadOnly Property HasRowID() As Boolean
        Get
            Return False
        End Get
    End Property

End Class

#End Region

Public MustInherit Class _Categories
    Inherits EasyObject

    Sub New()
        Dim _schema As New CategoriesSchema()
        Me.SchemaEntries = _schema.SchemaEntries
		Me.SchemaGlobal = "dbo"
    End Sub

	Public Overrides Sub FlushData()
		Me._whereClause = Nothing
		Me._aggregateClause = Nothing
		MyBase.FlushData()
	End Sub
		
	''' <summary>
	''' Loads the business object with info from the database, based on the requested primary key.
	''' </summary>
	''' <param name="CategoryID"></param>
	''' <returns>A Boolean indicating success or failure of the query</returns>
	Public Function LoadByPrimaryKey(ByVal CategoryID As Integer) As Boolean
		
		Select Case Me.DefaultCommandType
			Case CommandType.StoredProcedure
				Dim parameters As ListDictionary = New ListDictionary

				' Add in parameters
				parameters.Add(CategoriesSchema.CategoryID.FieldName, CategoryID)

				Return MyBase.LoadFromSql(Me.SchemaStoredProcedureWithSeparator & "daab_GetCategories", parameters, CommandType.StoredProcedure)
				
			Case CommandType.Text
                Me.Query.ClearAll()
                Me.Where.WhereClauseReset()
				Me.Where.CategoryID.Value = CategoryID
				Return Me.Query.Load()

			Case Else
				Throw New ArgumentException("Invalid CommandType", "commandType")
				
		End Select
		
	End Function

    ''' <summary>
    ''' Loads all records from the table.
    ''' </summary>
    ''' <returns>A Boolean indicating success or failure of the query</returns>
    Public Function LoadAll() As Boolean
	
		Select Case Me.DefaultCommandType
		
			Case CommandType.StoredProcedure
				Dim parameters As ListDictionary = Nothing
				Return MyBase.LoadFromSql(Me.SchemaStoredProcedureWithSeparator & "daab_GetAllCategories", parameters, CommandType.StoredProcedure)
				
			Case CommandType.Text
                Me.Query.ClearAll()
                Me.Where.WhereClauseReset()
				Return Me.Query.Load()
			
			Case Else
				Throw New ArgumentException("Invalid CommandType", "commandType")
				
		End Select

    End Function

    ''' <summary>
    ''' Adds a new record to the internal table.
    ''' </summary>
	Public Overrides Sub AddNew()
		MyBase.AddNew()
		Me.ApplyDefaults()
	End Sub

	''' <summary>
	''' Apply any default values to columns
	''' </summary>
	Protected Overrides Sub ApplyDefaults()
	End Sub

    Protected Overrides Function GetInsertCommand(commandType As CommandType) As DbCommand
	
		Dim dbCommand As DbCommand
		
        ' Create the Database object, using the default database service. The
        ' default database service is determined through configuration.
        Dim db As Database = GetDatabase()
	
		Select Case commandType
		
			Case CommandType.StoredProcedure
				Dim sqlCommand As String = Me.SchemaStoredProcedureWithSeparator & "daab_AddCategories"
				dbCommand = db.GetStoredProcCommand(sqlCommand)
				
				db.AddParameter(dbCommand, "CategoryID", DbType.Int32, 0, ParameterDirection.Output, True, 0, 0, "CategoryID", DataRowVersion.Default, Convert.DBNull)
				CreateParameters(db, dbCommand)

			Case CommandType.Text
                Me.Query.ClearAll()
				Me.Where.WhereClauseReset()
				For Each item As SchemaItem In Me.SchemaEntries
                    If Not item.IsComputed Then
                        If (item.IsAutoKey AndAlso Me.IdentityInsert) OrElse Not item.IsAutoKey Then
                            Me.Query.AddInsertColumn(item)
                        End If
                    End If
				Next
				dbCommand = Me.Query.GetInsertCommandWrapper()

				dbCommand.Parameters.Clear()
				If Me.IdentityInsert Then
					db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Default)
				Else
					db.AddParameter(dbCommand, "CategoryID", DbType.Int32, 0, ParameterDirection.Output, True, 0, 0, "CategoryID", DataRowVersion.Default, Convert.DBNull)
				End If

				CreateParameters(db, dbCommand)

			Case Else
				Throw New ArgumentException("Invalid CommandType", "commandType")
				
		End Select

        Return dbCommand

    End Function

    Protected Overrides Function GetUpdateCommand(commandType As CommandType) As DbCommand
	
		Dim dbCommand As DbCommand

        ' Create the Database object, using the default database service. The
        ' default database service is determined through configuration.
        Dim db As Database = GetDatabase()
	
		Select Case commandType
		
			Case CommandType.StoredProcedure
				Dim sqlCommand As String = Me.SchemaStoredProcedureWithSeparator & "daab_UpdateCategories"
				dbCommand = db.GetStoredProcCommand(sqlCommand)
		
				db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Current)
				CreateParameters(db, dbCommand)

			Case CommandType.Text
                Me.Query.ClearAll()
				For Each item As SchemaItem In Me.SchemaEntries
					If Not (item.IsAutoKey OrElse item.IsComputed)
						Me.Query.AddUpdateColumn(item)
					End If
				Next

				Me.Where.WhereClauseReset()
				Me.Where.CategoryID.Operator = WhereParameter.Operand.Equal
				dbCommand = Me.Query.GetUpdateCommandWrapper()

				dbCommand.Parameters.Clear()
				CreateParameters(db, dbCommand)
				db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Current)

			Case Else
				Throw New ArgumentException("Invalid CommandType", "commandType")
				
		End Select

        Return dbCommand

    End Function

    Protected Overrides Function GetDeleteCommand(commandType As CommandType) As DbCommand
	
		Dim dbCommand As DbCommand

        ' Create the Database object, using the default database service. The
        ' default database service is determined through configuration.
        Dim db As Database = GetDatabase()
	
		Select Case commandType
		
			Case CommandType.StoredProcedure
				Dim sqlCommand As String = Me.SchemaStoredProcedureWithSeparator & "daab_DeleteCategories"
				dbCommand = db.GetStoredProcCommand(sqlCommand)
		
				' Add primary key parameters
				db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Current)

			Case CommandType.Text
                Me.Query.ClearAll()
				Me.Where.WhereClauseReset()
				Me.Where.CategoryID.Operator = WhereParameter.Operand.Equal
				dbCommand = Me.Query.GetDeleteCommandWrapper()

				dbCommand.Parameters.Clear()
				db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Current)

			Case Else
				Throw New ArgumentException("Invalid CommandType", "commandType")
				
		End Select

        Return dbCommand

    End Function

    Private Sub CreateParameters(ByVal db As Database, ByVal dbCommand As DbCommand)
		
		db.AddInParameter(dbCommand, "CategoryName", DbType.String, "CategoryName", DataRowVersion.Current)
		db.AddInParameter(dbCommand, "Description", DbType.String, "Description", DataRowVersion.Current)
		db.AddInParameter(dbCommand, "Picture", DbType.Binary, "Picture", DataRowVersion.Current)

    End Sub

#Region " Properties "

	Public Overridable Property CategoryID() As Integer
        Get
			Return Me.GetInteger(CategoriesSchema.CategoryID.FieldName)
      End Get
        Set(ByVal Value As Integer)
			Me.SetInteger(CategoriesSchema.CategoryID.FieldName, Value)
      End Set
    End Property

	Public Overridable Property CategoryName() As String
        Get
			Return Me.GetString(CategoriesSchema.CategoryName.FieldName)
      End Get
        Set(ByVal Value As String)
			Me.SetString(CategoriesSchema.CategoryName.FieldName, Value)
      End Set
    End Property

	Public Overridable Property Description() As String
        Get
			Return Me.GetString(CategoriesSchema.Description.FieldName)
      End Get
        Set(ByVal Value As String)
			Me.SetString(CategoriesSchema.Description.FieldName, Value)
      End Set
    End Property

	Public Overridable Property Picture() As Byte()
        Get
			Return Me.GetByteArray(CategoriesSchema.Picture.FieldName)
      End Get
        Set(ByVal Value As Byte())
			Me.SetByteArray(CategoriesSchema.Picture.FieldName, Value)
      End Set
    End Property

    Public Overrides ReadOnly Property TableName() As String
        Get
            Return "Categories"
        End Get
    End Property

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -