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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:38:03+00:00 2026-05-13T17:38:03+00:00

I was thinking of implementing a per-object Repository (e.g. a Person repository, a State

  • 0

I was thinking of implementing a per-object Repository (e.g. a Person repository, a State repository etc.) before deciding on a line of business Repository instead BUT I still have a question regarding the passing in of an ID (identifier) type with a generic.

In a nutshell, a Person may have a GUID identifier, a State/County may have a int identifier, etc. With this in mind, how can I pass along a type that specifies the ID, er, type of the generic being passed in?

Here’s my attempt at the interface:

public interface IRepository<T, TID> where T : class where TID : Type
{        
    T Get(TID id);
    IList<T> GetAll();
    void Update(T entity);
    void Insert(T entity);
    void Delete(TID id);
}

You can see that T is the class (Person, State, etc.) and my intent is to have TID be the type that is used for the identifier, i.e. look at T Get(TID id).

This craps out with the compilation error: “The type ‘string’ cannot be used as type parameter ‘TID’ in the generic type or method ‘DumpWebApp.IRepository’. There is no implicit reference conversion from ‘string’ to ‘System.Type’.”

Another way of doing it would be to pass the actual element into the Get and Delete methods, I guess, but that seems a bit clunky.

Thanks for any suggestions – and incidentally, is returning IList acceptable for GetAll()? Why not IQueryable, or T[] ?

Mike K.

  • 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-13T17:38:04+00:00Added an answer on May 13, 2026 at 5:38 pm

    Just drop the where TID : Type constraint. That should do the trick.

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

Sidebar

Related Questions

I've been thinking of implementing this system, but can't help but feel there's a
I am thinking about implementing a program with finite state automaton in an OOP
I was thinking of implementing real time chat using a PHP backend, but I
I'm thinking of implementing the state design pattern on an ASP .NET Webform. The
I am thinking of implementing an easy Instant Messaging server in Java, but I
I was thinking of implementing a thumbs system, but mine would require a registration
I was thinking of implementing shortcut keys in a pet web application, I am
I am thinking of implementing a good licensing mechanism that has a good resistance
I'm thinking of implementing a Domain Driven Design approach (similar to the one described
I'm thinking of implementing the Screwturn Wiki for documenting the administration area of a

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.