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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:42:39+00:00 2026-05-26T02:42:39+00:00

For example I have 3 entities : product, tool, device. All of them have

  • 0

For example I have 3 entities : product, tool, device. All of them have “id” and “Name” attributes. Now I try to write a method to fill entity’s data into a combobox. But I don’t now how to create a method that can pass any entity into it. Something like code below :

    private comboBox FillCombobox(List<EntityType>)
    {
        using (dowacodbEntities dowacodbEntities = new dowacodbEntities())
        {
            comboBox comboBox = new comboBox();
            List<EntityType> EntityList = dowacodbEntities.EntityType.ToList();
            DataTable dt = new DataTable();
            dt.Columns.Add("id");
            dt.Columns.Add("Name");
            dt.Rows.Add(-1, "Choose one option");
            foreach (EntityType Entity in EntityList)
            {
                dt.Rows.Add(Entity.id, Entity.Name);
            }
            comboBox.ValueMember = dt.Columns[0].ColumnName;
            comboBox.DisplayMember = dt.Columns[1].ColumnName;
            comboBox.DataSource = dt;
            return combobox;
        }
    }

Which EntityType can be product, tool or device.

  • 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-26T02:42:39+00:00Added an answer on May 26, 2026 at 2:42 am

    Define interface:

    public interface IBaseEntity
    {
        int Id { get; }
        string Name { get; }
    }
    

    Implement that interface in your Product, Tool and Device classes (it can be implemented by your partial part if entities are autogenerated) and define your method as:

    private ... FillCombobox<T>(...) where T : class, IBaseEntity
    {
        using (var context = new Context())
        {
            var entities = context.CreateObjectSet<T>().ToList();
            ...
            foreach (IBaseEntity entity in entities)
            {
                dt.Rows.Add(entity.Id, entity.Name);
            }
            ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example I have 3 entities: Category Subcategory Product In SonataAdminBundle I'd like to
Let's take an example where we have two entities: ServiceProvider and TelephoneNumber . The
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
Example: I have a selector like this, which I give to another method as
Example: I have a method -myFooBarMethod:withFoo:bar:moreFoo: and inside the implementation of that method I
For example I have data model like this Entity: Store Entity: Inventory Entity:Product Attribute:
I have an application that uses Doctrine ORM for entities. I try to push
I generally try and keep all related entities in the same repository. The following
I have 2 entities for legacy db with composite keys, one of them has
Regarding the topic, some entities have multiplicity relationship I learned all of these in

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.