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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:21:52+00:00 2026-06-01T02:21:52+00:00

I’ve 3 different database tables that have the same 5 fields but those does

  • 0

I’ve 3 different database tables that have the same 5 fields but those does not have any foreign key relation as they are not keeping the same value in fact, but the equivalents; like: CompanyA table has productA and CompanyB has productB.

so I have 3 different collections include 3 fields that are equivalent. So what I’d like to do is to use a single class that has companyType and ProductName properties and use only one method to cast those 3 different collections to one and only class object, say ResultClass.

public class ResultClass
{
    public EnumCompanyType CompanyType { get; set; }
    public string ProductName { get; set; }

    public ICollection<ResultClass> ConvertAnything(ICollection<T> collection)
    {
        //Cast it to ResultClass

        return resultClassCollection;
    }
}

So that I can use this like:

ICollection<ProductA> aCollection = GetCompanyAData();
ICollection<ProductB> bCollection = GetCompanyBData();        
ConvertAnything(aCollection);
ConvertAnything(bCollection);

I’ve tried “dynamic” but actually don’t know the principle (neither have the knowledge); so I’ve messed it up and I think it’s not for this stuff.

I’ve tried to create an extension method but since the extension has no type for its parameter (as it is using ICollection), I can’t access the fields of the items (eg. properties)

I’m using LinqToSql and all the database table terms etc. belongs to this concept, nothing else.

edit:

I think I should made myself clear:
The multiple instances that I’m trying to avoid (or shouldn’t I, still thinking) is like below

public ICollection<ResultClass> ConvertAnythingForA(ICollection<ProductA> collection)
    {
        foreach(var item in collection)
        {
            var result = new ResultClass
                             {
                                 ProductName = item.ProductA,
                                 ProductType = EnumProductType.ProductA
                             };

            resultClassCollection.Add(result);
        }
        return resultClassCollection;
    }

public ICollection<ResultClass> ConvertAnythingForB(ICollection<ProductB> collection)
    {
        foreach(var item in collection)
        {
            var result = new ResultClass
                             {
                                 ProductName = item.ProductB,
                                 ProductType = EnumProductType.ProductB
                             };

            resultClassCollection.Add(result);
        }
        return resultClassCollection;
    }

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-01T02:21:54+00:00Added an answer on June 1, 2026 at 2:21 am

    I may not be understanding you completely, but since ProductA, ProductB etc have the same signature it seems like you’d want an interface like

    public interface IResultClass
    {
        int CompanyType { get; set; }
        string ProductName { get; set; }
    }
    

    And have those classes just implement the interface. You could work with collections of the interface that could have objects of the various types. If you need a convert anything method, it would look like

    public ICollection<IResultClass> ConvertAnything<T>(ICollection<T> collection) where T : IResultClass
        {
            return collection.Select(x => (IResultClass)x).ToList();
        }
    

    After comments- I see you that you are getting a non generic ICollection. Did you try something like this:

    public ICollection<IResultClass> ConvertAnything(ICollection collection)
        {
            var x = collection.Cast<IResultClass>();
            return x.ToList();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a reasonable size flat file database of text documents mostly saved in
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't

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.