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

  • Home
  • SEARCH
  • 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 6370275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:54:33+00:00 2026-05-25T00:54:33+00:00

The situation is that I have a table that models an entity. This entity

  • 0

The situation is that I have a table that models an entity. This entity has a number of properties (each identified by a column in the table). The thing is that in the future I’d need to add new properties or remove some properties. The problem is how to model both the database and the corresponding code (using C#) so that when such an occasion appears it would be very easy to just “have” a new property.

In the beginning there was only one property so I had one column. I defined the corresponding property in the class, with the appropriate type and name, then created stored procedures to read it and update it. Then came the second property, quickly copy-pasted, changed name and type and a bit of SQL and there it was. Obviously this is not a suitable model going forward. By this time some of you might suggest an ORM (EF or another) because this will generate the SQL and code automatically but for now this is not an option for me.

I thought of having only one procedure for reading one property (by property name) and another one to update it (by name and value) then some general procedures for reading a bunch or all properties for an entity in the same statement. This may sound easy in C# if you consider using generics but the database doesn’t know generics so it’s not possible to have a strong typed solution.

I would like to have a solution that’s “as strongly-typed as possible” so I don’t need to do a lot of casting and parsing. I would define the available properties in code so you don’t go guessing what you have available and use magic strings and the like. Then the process of adding a new property in the system would only mean adding a new column to the table and adding a new property “definition” in code (e.g. in an enum).

  • 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-05-25T00:54:33+00:00Added an answer on May 25, 2026 at 12:54 am

    It sounds like you want to do this:

    MyObj x = new MyObj();
    x.SomeProperty = 10;
    

    You have a table created for that, but you dont want to keep altering that table when you add

    x.AnotherProperty = "Some String";
    

    You need to normalize the table data like so:

    -> BaseTable
       RecordId, Col1, Col2, Col3
    
    -> BaseTableProperty
       PropertyId, Name
    
    -> BaseTableValue
       ValueId, RecordId, PropertyId, Value
    

    Your class would look like so:

     public class MyObj
     {
          public int Id { get; set; }
          public int SomeProperty { get; set; }
          public string AnotherProperty { get; set; }
     }
    

    When you create your object from your DL, you enumerate the record set. You then write code once that inspect the property as the same name as your configuration (BaseTableProperty.Name == MyObj.<PropertyName> – and then attempt the type cast to that type as you enumerate the record set.

    Then, you simply add another property to your object, another record to the database in BaseTableProperty, and then you can store values for that guy in BaseTableValue.

    Example:

     RecordId
     ========
     1
    
     PropertyId          Name
     ==========          ====
     1                   SomeProperty
    
     ValueId     RecordId       PropertyId      Value
     =======     ========       ==========      =====
     1           1              1               100
    

    You have two result sets, one for basic data, and one joined from the Property and Value tables. As you enumerate each record, you see a Name of SomeProperty – does typeof(MyObj).GetProperty("SomeProperty") exist? Yes? What it it’s data type? int? Ok, then try to convert “100” to int by setting the property:

     propertyInfo.SetValue(myNewObjInstance, Convert.ChangeType(dbValue, propertyInfo.PropertyType), null);
    

    For each property.

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

Sidebar

Related Questions

I have a situation that has been partially covered by other answers at SO,
I have a situation where I'm starting a number of objects that, when they
I have a situation that I cannot change: one database table (table A) accepts
Currently in our enterprise we have a situation that i think it's not very
I've been working on optimizing a query and have ran into a situation that's
Situation: I have a simple XML document that contains image information. I need to
I have a situation where I have two entities that share a primary key
I have the following situation: I have a certain function that runs a loop
Here is my situation: I have an application that use a configuration file. The
I have the following situation: There is a tool that gets an XSLT from

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.