Avatar of Craig Yellick
Craig Yellick
Flag for United States of America

asked on 

Inherit from System.Data.DataRow; the DataRowBuilder dilemma

I need to isolate access to my data access layer (DAL) from my user interface layer through a business logic layer (BLL). I love the way ADO.NET DataTables and DataRows work and need to leverage all the built-in binding that they do, so I want to use DataSets as the foundation of my DAL. To fully isolate the user interface from the DAL the BLL needs to subclass the DataTable and DataRow objects.

It does not appear that it is possible to inherit from DataRow due to a dependency on a non-constructible, non-inheritable DataRowBuilder class. I'm OK with creating my own version of DataRowBuilder if that's what it takes.

Code sample based on Northwind is below.  The Northwind dataset was built with the VS drag-and-drop interface, by simply dropping the Shippers table. Please disregard the implementation of GetShipper, it is not the point of the example.

The point of the example, and the essence of my question, is how to make the BLL.Shipper class (shown below) inherit from the DAL's Northwind.ShipperRow.

-- Craig

PS: I've seen a tendency for people to assert "why do you want to do that" in response to these type of questions. I can explain if necessary but it should be enough to want to separate the UI layer from the data access layer and have it instead use a business logic layer exclusively.  
Namespace BLL
 
  Public Class ShipperEntity
 
    Public Function GetShipper(ByVal ShipperID As Integer) As Shipper
      Dim ad As New NorthwindTableAdapters.ShippersTableAdapter
      Dim t As Northwind.ShippersDataTable = ad.GetData
      Dim r As Northwind.ShippersRow = _
        DirectCast(t.Rows(ShipperID - 1), Shipper)
      Return DirectCast(r, Shipper)
    End Function
 
  End Class
 
  Public Class Shipper
    Inherits Northwind.ShippersRow
  End Class
 
End Namespace

Open in new window

Editors IDEs.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
Craig Yellick

8/22/2022 - Mon