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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:20:52+00:00 2026-05-15T02:20:52+00:00

I’ve gotten myself stuck on how to handle inheritance in my model when it

  • 0

I’ve gotten myself stuck on how to handle inheritance in my model when it comes to my controllers/views.

Basic Model:

public class Procedure : Entity
{
    public Procedure() { }

    public int Id { get; set; }
    public DateTime ProcedureDate { get; set; }
    public ProcedureType Type { get; set; }
}

public ProcedureA : Procedure
{
    public double VariableA { get; set; }
    public int VariableB { get; set; }
    public int Total { get; set; }
}

public ProcedureB : Procedure
{
    public int Score { get; set; }
}

etc… many of different procedures eventually.

So, I do things like list all the procedures:

public class ProcedureController : Controller
{
    public virtual ActionResult List()
    {
        IEnumerable<Procedure> procedures = _repository.GetAll();
        return View(procedures);
    }
}

but now I’m kinda stuck. Basically, from the list page, I need to link to pages where the specific subclass details can be viewed/edited and I’m not sure what the best strategy is.

I thought I could add an action on the ProcedureController that would conjure up the right subclass by dynamically figuring out what repository to use and loading the subclass to pass to the view. I had to store the class in the ProcedureType object. I had to create/implement a non-generic IRepository since I can’t dynamically cast to a generic one.

public virtual ActionResult Details(int procedureID)
{
    Procedure procedure = _repository.GetById(procedureID, false);
    string className = procedure.Type.Class;
    Type type = Type.GetType(className, true);
    Type repositoryType = typeof (IRepository<>).MakeGenericType(type);
    var repository = (IRepository)DependencyRegistrar.Resolve(repositoryType);
    Entity procedure = repository.GetById(procedureID, false);
    return View(procedure);
}

I haven’t even started sorting out how the view is going to determine which partial to load to display the subclass details.

I’m wondering if this is a good approach? This makes determining the URL easy. It makes reusing the Procedure display code easy.

Another approach is specific controllers for each subclass. It simplifies the controller code, but also means many simple controllers for the many procedure subclasses. Can work out the shared Procedure details with a partial view. How to get to construct the URL to get to the controller/action in the first place?

Time to not think about it. Hopefully someone can show me the light. 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-05-15T02:20:53+00:00Added an answer on May 15, 2026 at 2:20 am

    Well….what I did above worked well, but it was totally unnecessary.

    What WAS necessary was that I had my mappings in place (or at least stuck to types I had mapped). I realized moments ago while debugging something else that I had everything I needed without the dynamic casting magic. Just this:

    public virtual ActionResult Details(int procedureID)
    {
        Procedure procedure = _repository.GetById(procedureID, false);
        return View(procedure);
    }
    

    This works due to the magic of joined-subclasses in nhibernate. Ask for superclass and you’ll get an instance of the appropriate subclass cast as the superclass (if it’s all set up properly, that is)

    Way cool, but now I’m wondering about performance. I profiled the SQL call and it uses outer joins across all the child tables. That smells of bottleneck when there’s lots of tables (40-50) and many records. Will have to ponder and perhaps inquire.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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

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.