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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:23:18+00:00 2026-06-16T12:23:18+00:00

I have come across a situation where the answer should be really straight forward,

  • 0

I have come across a situation where the answer should be really straight forward, but it eludes me.

public class Note
{

    #region Properties

    public int Id { get; set; }
    public int ClientId { get; set; }
    public int CandidateId { get; set; }
    public int TypeId { get; set; }
    public DateTime DateCreated { get; set; }
    public string UserId { get; set; }
    public string UserName { get; set; }
    public string Message { get; set; }

    #endregion

    #region Methods

    public void Save()
    {

    }

    #endregion

}

public class History : Note
{
}

As you can see, History inherits Note. They are exactly the same, the only difference between the two is the type Id.

I have this function when getting data from the database

    public static Note Parse(SqlDataReader dr)
    {
        int TypeId = Convert.ToInt32(dr["TypeId"]);
        Note Note;

        if (TypeId == 1)
            Note = new Note();
        else
            Note = new History();

        Note.Id = Convert.ToInt32(dr["Id"]);
        Note.TypeId = TypeId;
        if (dr["ClientId"] != DBNull.Value) Note.ClientId = Convert.ToInt32(dr["ClientId"]);
        if (dr["CandidateId"] != DBNull.Value) Note.CandidateId = Convert.ToInt32(dr["CandidateId"]);
        Note.DateCreated = Convert.ToDateTime(dr["DateCreated"]);

        Note.UserId = Convert.ToString(dr["UserId"]);
        Note.UserName = Convert.ToString(dr["UserName"]);
        Note.Message = Convert.ToString(dr["Message"]);

        return Note;
    }

And then on my MVC page I have this:

<ol id="interview-comments">                                
@foreach (Note Note in Model.Notes().OfType<Note>())
{  
}
</ol>

<ol id="history-comments">                             
@foreach (History Note in Model.Notes().OfType<History>())
{  
}
</ol>

My question is simple. Is this the correct way to do it?

/r3plica

  • 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-16T12:23:19+00:00Added an answer on June 16, 2026 at 12:23 pm

    If this is the whole picture I wouldn’t use inheritance here.
    You said that Note and History items had different TypeId:s.

    Then I would do the following:

    @foreach(var item in Model.Notes().Where(x => x.TypeId == Note.NoteTypeId))
    {
    }
    
    //and
    
    @foreach(var item in Model.Notes().Where(x => x.TypeId == Note.HistoryTypeId))
    {
    }
    
    public class Note
    {
      public static int HistoryTypeId = 1;
      public static int NoteTypeId = 0;
      /* ... the rest of the implementation */
    }
    

    You could also change TypeId to an enum and “hide” some of the magic numbers

    Edit:
    Depending on the usage you could also implement the check for Historic notes as a property on Note.

    public class Note
    {
      /* ... other properties ... */
      public bool IsHistoric { get { return this.TypeId != 1; } }
    }
    

    And then the check would simple be

    @foreach(var note in Model.Notes().Where(x => x.IsHistoric))
    {
    }
    
    // and
    
    @foreach(var note in Model.Notes().Where(x => !x.IsHistoric())
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across a situation (which I think is weird but is possibly
I have come across a situation where my program hangs, looks like deadlock. But
I have come across loop-unrolling but what other types of compiler optimization are there
I'm making a big C project and I have never come across a situation
I have come across a situation where it would be better to represent a
I have come across this situation. In the hash1 first column is the key
I have come across a situation I have not encountered before using the IF
I'm using C# 4.0 and have come across a situation where I have to
I have come across an awkward situation where I would like to have a
I have come across the same problem, but maybe I can give a little

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.