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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:42:59+00:00 2026-06-07T03:42:59+00:00

Right now, I have an enum like this: public enum ReferenceType { Language =

  • 0

Right now, I have an enum like this:

public enum ReferenceType
{
    Language = 1,
    Period = 2,
    Genre = 3
}

Language, Period, and Genre are all entity classes that map back to tables in my database. I also have model classes that map almost 1 to 1 with the entity classes, which I then display in a view.

I also have a service method like this:

List<Model> Get<Model, Entity>()
        where Model : BaseModel
        where Entity : BaseEntity;

I can call it like Service.Get<LanguageModel, Language>() and it will return every row from table Language from my database and automatically convert them into LanguageModels, which I’ll then display in my view.

I want to create a wrapper method around the Get() method where you simply need to pass in an integer and it will call my Get() method filling in the entity and model class types automatically. The only problem is I’m having a hard time wrapping my head around the actual implementation behind this.

The pseudo-code would be along the lines of:

  1. Call WrapperGet((int)ReferenceType.Genre)
  2. Wrapper method resolves the entity type (Genre) and model type (GenreModel)
  3. Call the Get() method with the resolved entity and model types, so it’d be Get<GenreModel, Genre>()
  4. Return the results

How would I actually go implementing this in C#?

  • 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-07T03:42:59+00:00Added an answer on June 7, 2026 at 3:42 am

    If you want strongly-typed results, you’ll have to forgo the idea of passing an int or enum in, and switch to calling Get directly or making methods like this:

    List<LanguageModel> GetLanguages() { return Get<LanguageModel, Language>(); }
    

    If weakly typed works for you, then I’d go with Saeed’s solution, but the types need a little changing to work. Model was a generic type in your example, so presumably he meant List<BaseModel> as the return type. But a List<LanguageModel> isn’t a List<BaseModel>! You can resolve this by either making it return IEnumerable<BaseModel> or changing Get to return a List<BaseModel>, or change it afterwards with return new List<BaseModel>(Get<...

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

Sidebar

Related Questions

The system have a plain enum like this, public enum SomeEnum : short {
Right now I have a script that will get the last five files in
Right now I have a function, in a class that is used to listen
Right now I have a link that causes a hidden div to appear when
Right now I have a foreach loop that grabs the first link with an
Right now I have a PHP file that does a MYSQL query and then
Right now I have this SQL query which is valid but always times out:
I have a bunch of stored, serialized classes (that all inherit from a base
I have a class like that: public class Customer { public string Name {get;
Hi I have this enum currently [Serializable] public enum Country { US = 1,

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.