I'm currently trying to create a kind of model in vb.net that can be used to create / retrieve records in a database.
I created a model of the main class with a common function for retrieving datasets, for example. Model.find (). Now I would like to create classes that inherit the main class of the model, for example. separate for users: UserModel.find () => "SELECT * FROM users".
Now I need to find a way to tell the class which it should use. I was thinking about the abstract string "table", which is a constant in each "child model", but how can this be implemented since it is not possible to override common members?
Thanks in advance!
Change Perhaps this will simplify things a bit, which I mean:
Public Class Model Public Shared _controller As Controller Public Shared table As String Protected Shared tableFields As String() Shared reader As Npgsql.NpgsqlDataReader Public Shared Function find() Dim a As ArrayList = New ArrayList 'Test if the tablefields are already known to the class, if not, get them If tableFields Is Nothing Then getTableFields() End If Dim query As String = "SELECT " + String.Join(", ", tableFields) + " FROM " + table reader = _controller.executeReader(query) While reader.Read o = New Model Dim v As New Hashtable For Each field In tableFields v(field) = reader(field) Next o.values = v a.Add(o) End While reader.Close() Return DirectCast(a.ToArray(GetType(Model)), Model()) End Function Public values As Hashtable Public Sub New() End Sub End Class
So, I need a generic method that finds all the records in the database and returns an array of instances of its own type, for example. Model(). This is why I wanted to keep the general search method and not tied to the instance.
stex
source share