Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9022753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:35:48+00:00 2026-06-16T05:35:48+00:00

I am attempting to create an application which interacts with a database. I program

  • 0

I am attempting to create an application which interacts with a database.

I program in many languages and I loved how easy it was to use Models in an MVC based application.

So my question is, trying to replicate this functionality, I have 2 classes as follows:

Base Class:

public class BaseModel
{
    protected string TableName { get; set; }

    public BaseModel()
    {         
    }

    public void Save()
    {
        // Save data in derived class to table stored in TableName
    }
}

Derived Class:

public class UserModel : BaseModel
{
    public string Field1 { get; set; }
    public string Field2 { get; set; }

    public UserModel()
    {
        base.TableName = "user";
    }
}

From my main application, i want to be able to do the following:

public class Class1
{
    public Class1()
    {
        UserModel model = new UserModel();
        model.Field1 = "Value1";
        model.Field2 = "Value2";
        model.Save();
    }
}

Here is where i have hit a problem. I cannot for the life in me figure out, how i would be able to access the properties in UserModel so they can be saved to the database table specified in in the constructor of UserModel to the BaseModel.

Hope this made sense. 🙂

This code is not my working code, it is a very simple representation of what i would like to achieve so Fields and properties (validators etc) have been dumbed down for ease of reading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:35:49+00:00Added an answer on June 16, 2026 at 5:35 am

    This is in general solved by utilize abstract functions at the base level and then overriding them with specifics in the derived class. So would would set up a call tree in the base but functions that need to know the details of the derived class would be implemented in the derived class.

    public class BaseModel
    {
        protected string TableName { get; set; }
    
        public BaseModel()
        {         
        }
    
        public abstract void Save();
    }
    

    In this case where you have one concrete data representation manifested in a base class it may be better to create a DTO object which your business classes take in a utilize. This is the approch of most of the frameworks like entity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to create a simple database application which keeps track of loans
I am attempting to write a VB.net application which will allow users to create
I'm attempting to create a small application in which I can make a poul
I'm attempting to create (in XCode) a Tabbed Application, which houses in one of
I am attempting to create an application which, at some point, I would like
I am attempting to create an application which has a edit text view and
I'm attempting to create an application for SharePoint. I would like this application to
I am attempting to create/deploy an application onto the Redhat OpenShift Express platform, and
I'm attempting to create Data Access Layer for my web application. Currently, all datatables
In a Silverlight 3.0 application I'm attempting to create a rectangle in a canvas

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.