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 8875185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:54:48+00:00 2026-06-14T18:54:48+00:00

The database I’m working with on a Windows Forms application has a lot of

  • 0

The database I’m working with on a Windows Forms application has a lot of tables that consist of a primary key int identity field, a varchar description and a one-to-one relationship with another table where its id and description are used.

One example of my C# POCOs mapped to the database using Entity Framework Code First is:

public class OtherClass
{
  public int Id { get; set; }
  public string Description { get; set; }
}

public class Foo
{
  public int Id { get; set; }
  public string Description { get; set; }
  public OtherClass OtherClassProperty { get; set; }
}

Because those classes like “Foo” all share the same structure, I’m creating one basic form that should be able to work with all classes like this one.

My problem is that all of those classes have different property names for its Id and Description (sometimes called Name, for example). Not to mention that the other class they reference is always different.

My first thought was to create an interface requiring the implementation of properties with fixed names: Id, Description, KeyId, KeyDescription. Those properties would be implemented on each class but only pointing to the “real properties”. Like this:

public class Foo : MyInterface
{
  public int Id { get; set; }
  public string Description { get; set; }
  public OtherClass OtherClassProperty { get; set; }  

  //Interface implementation
  public int CommonId { get { return this.Id; } set { this.Id = value; } }
  public int CommonDescription { get { return this.Description; } set { this.Description = value; } }
  public int CommonKeyId { get { return this.OtherClassProperty.Id; } set { this.OtherClassProperty.Id = value; } }
  public int CommonKeyDescription { get { return this.OtherClassProperty.Description; } set { this.OtherClassProperty.Description = value; } }
}

I have the impression that there might be a better solution for this. I can also imagine implementing property attributes and using reflection to check at runtime and get the properties.

Would anyone have a suggestion for this situation?

Thanks in advance.

  • 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-14T18:54:49+00:00Added an answer on June 14, 2026 at 6:54 pm

    Fixation of names sounds like a good direction. Take a look at Adapter pattern for a more formal approach to this.

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

Sidebar

Related Questions

Database has tables Photos and PhotoAlbums. I need a query that will select all
Database has table X and tables An, Bn, Cn, Dn that inherits from X.
A database application that I'm currently working on, stores all sorts of settings in
Our database currently doesn't define primary keys on any tables. All of the id
Database: Sybase ASE 15.0.3 Tables: authors(int author_id, varchar(20) author_name) books(int author_id,int number_of_pages) I need
Database table Language languageID (Primary key) language People <%: Html.DropDownList(SprakID, new SelectList(ViewData[Sprak] as IEnumerable,
Database: db.execSQL(CREATE TABLE + TABLE_NAME_NOTE + ( + BaseColumns._ID + INTEGER PRIMARY KEY, +
My database table has a column that contains SQL timestamps (eg. 2009-05-30 19:43:41). I
Database resources, that can be accessed from webpage that I'm currently working on, have
My DataBase Table Structure is like this : ID(Primary Key ) , Title (Nvarchar)

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.