VB.NET Code to Create a Business Entity

Public Class ProductBusinessEntity? Inherits EPS.Business.BusinessObjects.BusinessEntity Public Sub New() MyBase.New() End Sub Public Sub New(ByVal itemId As Guid ) MyBase.New(itemId) End Sub Public Overrides Function GetBusinessObject() As EPS.Business.BusinessObjects.IBusinessObject Dim oBiz As New ItemBusinessObject Return CType(oBiz, EPS.Business.BusinessObjects.IBusinessObject ) End Function Public Property Name() As String Get Return Me.GetFieldValue("ProductName").ToString() End Get Set(ByVal Value As String) Me.SetFieldValue("ProductName", Value) End Set End Property Public Property QuantityPerUnit() As String Get Return Me.GetFieldValue("QuantityPerUnit").ToString() End Get Set(ByVal Value As String) Me.SetFieldValue("QuantityPerUnit", Value) End Set End Property Public ReadOnly Property TheoreticalUnits() As Integer Get Dim iOne As Integer Dim iTwo As Integer iOne = CType(Me.GetFieldValue("UnitsInStock"), Integer) iTwo = CType(Me.GetFieldValue("UnitsOnOrder"), Integer) Return iOne + iTwo End Get End Property End Class

Note: Make sure you pay attention to data types. GetFieldValue() for instance deals with variants (objects). However, properties return typed fields. In VB.NET, you can get away without using CType() to convert types if option strict is off. However, all our real-life projects will have option strict on, so you may find yourself re-writing a whole lot of your code (and no, we won't even feel sorry for you... ;-)


Last Updated: 8/7/2006