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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:24:21+00:00 2026-05-27T06:24:21+00:00

I am learning Nhibernate 3.0. In one of the sample code examples, it creates

  • 0

I am learning Nhibernate 3.0. In one of the sample code examples, it creates an abstract base entity class:

public abstract class Entity<T> where T : Entity<T>

then, make the Customer entity inherit from the Entity base class:

public class Customer : Entity<Customer>

I understand it’s an abstract generic class, and it is using the where keyword to make sure the type T is Entity<T>, this is where I get confused.

Customer inherits from “Entity<Customer>“, this “Entity<Customer>” takes “Customer” as T, but this Customer is not “Entity<T>“.

Please help me to understand this, I’m really confused by this generic class.

  • 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-27T06:24:22+00:00Added an answer on May 27, 2026 at 6:24 am

    You said

    customer inherits from “Entity”, this “Entity” takes “Customer” as T,
    but this customer is not “Entity”

    That doesn’t make any sense because that’s what inheritance means. It establishes an “is a” relationship. So in fact a Customer is an Entity

    Sorry that was based on the code with the generics stripped out because it wasn’t in a code block.

    The same principle is still valid though. It’s just a little confusing because it looks like it’s a recursive definition, but it’s not.

    Think of it as Customer inherits from Entity There just happens to be methods or fields that depend on the generic parameter being itself e.g. Customer. I’m not familiar with NHibernate so I don’t know what the rest of Entity<T> looks like, but I imagine it has some methods that use it’s own type as a generic parameter.

    Say for instance it has a method called

    public IEnumerable<T> GetEntities() 
    

    that returned a list of it’s own instances. It needs that method to return the concrete type rather than the base type. So in the Customer class, that method would be

    public IEnumerable<Customer> GetEntities<Customer>() 
    

    If it didn’t have the generic parameter, it could only return IEnumerable<Entity>

    That’s just an example of how it could be used, I don’t know how it’s actually used.

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

Sidebar

Related Questions

I am just learning NHibernate. I have been using examples from the documentation and
I'm learning NHibernate and was looking at some code recently where NHibernate was used
Can any one share some information about the sample application using hibernate for learning.
I'm learning NHibernate to learn a more robust ORM than linq to sql, but
I have just started learning NHibernate. Over the past few months I have been
The setup: Winform/ASP.NET MVC projects. Learning NHibernate SQL-Server driven apps I work with clients
all! I am learning NHibernate now and I would like to know is it
I am currently learning Hibernate and the Java Persistence API. I have an @Entity
I'm learning NHibernate and hoping you guys could help me a bit about Tag
I've been reading/learning more about Spring lately, and how one would use Spring 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.