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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:16:05+00:00 2026-06-09T18:16:05+00:00

From a previous thread I asked how to get a registry from an id

  • 0

From a previous thread I asked how to get a registry from an id in a generic way, the answer I got was this:

    public class DBAccess
{
    public virtual DataBaseTable GetById<DataBaseTable>(int id, Table<DataBaseTable> table) where DataBaseTable : class
    {
        var itemParameter = Expression.Parameter(typeof(DataBaseTable), "item");
        var whereExpression = Expression.Lambda<Func<DataBaseTable, bool>>
            (
            Expression.Equal(
                Expression.Property(
                    itemParameter,
                    "Id"
                    ),
                Expression.Constant(id)
                ),
            new[] { itemParameter }
            );
        return table.Where(whereExpression).Single();
    }
}

Which works nice, but now I’m stuck not knowing how to get any of its attributes, to give a concrete question, how could I make this below function work?

    public static int GetRelatedTableId<DataBaseTable>
    (Table<DataBaseTable> table,String RelatedTableId) where DataBaseTable : class
    {
        DBAccess RegistryGet = new DBAccess();    
        DataBaseTable tab = RegistryGet.GetById<DataBaseTable>(id, table);
        return tab.getAttributeByString(RelatedTableId);//i just made this up
    }

Update Solution

Thanks to the link below i managed to solve this

    public static int GetRelatedTableId<DataBaseTable>
    (Table<DataBaseTable> table,String RelatedTableId) where DataBaseTable : class
    {
        DBAccess RegistryGet = new DBAccess();    
        DataBaseTable tab = RegistryGet.GetById<DataBaseTable>(id, table);
        return (int)(tab.GetType().GetProperty(RelatedTableId)).GetValue(tab, null);
    }
  • 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-09T18:16:06+00:00Added an answer on June 9, 2026 at 6:16 pm

    If your property name is only known at runtime, then you can use reflection to inspect the type DataBaseTable, find the property of interest by name, and then retrieve its value from your instance tab.

    See the answer to this question for an example: How can I get the value of a string property via Reflection?

    Clarification: Yes, your type is a generic argument, but typeof(DataBaseTable) or tab.GetType() will still allow you to inspect the particular type being used.

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

Sidebar

Related Questions

I tried adding the code from this previous thread, but it did not work
Note: This question has broadened in scope from previous revisions. I have tried to
Is there a way to cache pages from previous visitors and then share that
I am trying to figure out this error from previous 3 hours. By searching,
This is related to my previous thread: SQL Query takes about 10 - 20
To follow from my previous question about virtual and multiple inheritance (in a cross
I asked the question about multiple rows in a previous thread, but now I
This is continued from thread: Python array multiply I need to multiply array vs
This is my previous thread about using ajax to check availability of username when
This is a follow up question from my previous one found here I need

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.