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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:05:40+00:00 2026-05-19T01:05:40+00:00

We are using an extractor application that will export data from the database to

  • 0

We are using an extractor application that will export data from the database to csv files. Based on some condition variable it extracts data from different tables, and for some conditions we have to use UNION ALL as the data has to be extracted from more than one table. So to satisfy the UNION ALL condition we are using nulls to match the number of columns.

Right now all the queries in the system are pre-built based on the condition variable. The problem is whenever there is change in the table projection (i.e new column added, existing column modified, column dropped) we have to manually change the code in the application.

Can you please give some suggestions how to extract the column names dynamically so that any changes in the table structure do not require change in the code?


My concern is the condition that decides which table to query. The variable condition is
like

  • if the condition is A, then load from TableX
  • if the condition is B then load from TableA and TableY.

We must know from which table we need to get data. Once we know the table it is straightforward to query the column names from the data dictionary. But there is one more condition, which is that some columns need to be excluded, and these columns are different for each table.

I am trying to solve the problem only for dynamically generating the list columns. But my manager told me to make solution on the conceptual level rather than just fixing. This is a very big system with providers and consumers constantly loading and consuming data. So he wanted solution that can be general.

So what is the best way for storing condition, tablename, excluded columns? One way is storing in database. Are there any other ways? If yes what is the best? As I have to give at least a couple of ideas before finalizing.

Thanks,

  • 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-19T01:05:40+00:00Added an answer on May 19, 2026 at 1:05 am

    Ok, MNC, try this for size (paste it into a new console app):

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Test.Api;
    using Test.Api.Classes;
    using Test.Api.Interfaces;
    using Test.Api.Models;
    
    namespace Test.Api.Interfaces
    {
        public interface ITable
        {
            int Id { get; set; }
            string Name { get; set; }
        }
    }
    
    namespace Test.Api.Models
    {
        public class MemberTable : ITable
        {
            public int Id { get; set; }
            public string Name { get; set; }
        }
        public class TableWithRelations
        {
            public MemberTable Member { get; set; }
            // list to contain partnered tables
            public IList<ITable> Partner { get; set; }
    
            public TableWithRelations()
            {
                Member = new MemberTable();
                Partner = new List<ITable>();
            }
        }
    }
    
    namespace Test.Api.Classes
    {
        public class MyClass
        {
            private readonly IList<TableWithRelations> _tables;
    
            public MyClass()
            {
                // tableA stuff
                var tableA = new TableWithRelations { Member = { Id = 1, Name = "A" } };
                var relatedclasses = new List<ITable>
                 {
                    new MemberTable
                    {
                       Id = 2,
                       Name = "B"
                    }
                 };
                tableA.Partner = relatedclasses;
    
    
                // tableB stuff
                var tableB = new TableWithRelations { Member = { Id = 2, Name = "B" } };
                relatedclasses = new List<ITable>
                 {
                    new MemberTable
                    {
                       Id = 3,
                       Name = "C"
                    }
                 };
                tableB.Partner = relatedclasses;
    
    
                // tableC stuff
                var tableC = new TableWithRelations { Member = { Id = 3, Name = "C" } };
                relatedclasses = new List<ITable>
                 {
                    new MemberTable
                    {
                       Id = 2,
                       Name = "D"
                    }
                 };
                tableC.Partner = relatedclasses;
    
    
                // tableD stuff
                var tableD = new TableWithRelations { Member = { Id = 3, Name = "D" } };
                relatedclasses = new List<ITable>
                 {
                    new MemberTable
                    {
                       Id = 1,
                       Name = "A"
                    },
                    new MemberTable
                    {
                       Id = 2,
                       Name = "B"
                    },
                 };
                tableD.Partner = relatedclasses;
    
                // add tables to the base tables collection
                _tables = new List<TableWithRelations> { tableA, tableB, tableC, tableD };
            }
    
            public IList<ITable> Compare(int tableId, string tableName)
            {
                return _tables.Where(table => table.Member.Id == tableId
                                && table.Member.Name == tableName)
                            .SelectMany(table => table.Partner).ToList();
            }
        }
    }
    
    namespace Test.Api
    {
        public class TestClass
        {
            private readonly MyClass _myclass;
            private readonly IList<ITable> _relatedMembers;
    
            public IList<ITable> RelatedMembers
            {
                get { return _relatedMembers; }
            }
    
            public TestClass(int id, string name)
            {
                this._myclass = new MyClass();
                // the Compare method would take your two paramters and return
                // a mathcing set of related tables that formed the related tables
                _relatedMembers = _myclass.Compare(id, name);
                // now do something wityh the resulting list
            }
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            // change these values to suit, along with rules in MyClass
            var id = 3;
            var name = "D";
            var testClass = new TestClass(id, name);
    
            Console.Write(string.Format("For Table{0} on Id{1}\r\n", name, id));
            Console.Write("----------------------\r\n");
            foreach (var relatedTable in testClass.RelatedMembers)
            {
                Console.Write(string.Format("Related Table{0} on Id{1}\r\n",
                          relatedTable.Name, relatedTable.Id));
            }
            Console.Read();
        }
    }
    

    I’ll get back in a bit to see if it fits or not.

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

Sidebar

Related Questions

No related questions found

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.