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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:17:39+00:00 2026-05-19T23:17:39+00:00

I am learning MVC 3 and I have not found people using some logic

  • 0

I am learning MVC 3 and I have not found people using some logic codes inside a property of a data model class.

They do the data model class as follows (for example):

public class Customer
{
    public int CustomerId {get;set;}
    //other properties without any logic code.
}

Is it ok to have logic codes inside a property as follows?

public class Customer
{
    private int customerId;
    public int CustomerId {
       get{return customerId;}
       set
       {
         customerId=value;
         // some logic codes go here.
       }
    }
    //other properties go here.
}

Edit 1:

This is my real scenario:

Child table data model:

namespace MvcApplication1.Models
{
    public class Choice
    {
        public int ChoiceId { get; set; }
        public string Description { get; set; }
        public bool IsCorrect { get; set; }
        public QuizItem QuizItem { get; set; }
    }
}

Parent table data model:

namespace MvcApplication1.Models
{
    public class QuizItem
    {
        public int QuizItemId { get; set; }
        public string Question { get; set; }

        private IEnumerable<Choice> choices;
        public IEnumerable<Choice> Choices
        {
            get { return choices; }

            set
            {
                choices = value;
                foreach (var x in choices)
                    x.QuizItem = this;
            }
        }
    }
}

Consumer:

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {


            var data = new List<QuizItem>{
                new QuizItem
                {
                    QuizItemId = 1,
                    Question = "What color is your hair?",
                    Choices = new Choice[]{
                        new Choice{ ChoiceId=1, Description="Black.", IsCorrect=true},
                        new Choice{ ChoiceId=2, Description="Red.", IsCorrect=false},
                        new Choice{ ChoiceId=3, Description="Yellow.", IsCorrect=false}
                    }
                },
                new QuizItem
                {
                    QuizItemId = 2,
                    Question = "What color is your noze?",
                    Choices = new Choice[]{
                        new Choice{ChoiceId=1, Description="Pink.", IsCorrect=false},
                        new Choice{ChoiceId=2, Description="Maroon.", IsCorrect=true},
                        new Choice{ChoiceId=3, Description="Navy Blue.", IsCorrect=false}
                    }
                }
            };


            return View(data);
        }

    }
}
  • 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-19T23:17:39+00:00Added an answer on May 19, 2026 at 11:17 pm

    This calls for a method. Two reasons why:

    • I don’t recommend setters for Collections
      • Property Usage Guidelines – Setting a property for each item in collection every time property is set is expensive and should not be in a property. A method is preferred instead.
    • Code (that you have in your case) in setter causes enough side-effects to disqualify use of property
      • Setters for collection type properties – A discussion on StackOverflow regarding setters for collections.

    I suggest following:

    public class QuizItem
    {
        public int QuizItemId { get; set; }
        public string Question { get; set; }
    
        private IEnumerable<Choice> choices;
        public IEnumerable<Choice> Choices
        {
            get { return choices; }
        }
    
        public void SetChoices(IEnumerable<Choice> choices)
        {
            foreach (var x in choices)
                x.QuizItem = this;
    
            this.choices = choices;                
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a little MVC system (learning) and I have some problems with showing
I'm learning ASP.NET MVC Framework, From some articles like this , it seems that
Where can I find a good tutorial on learning ASP.NET MVC using VB.net 2008
Good morning, I'm learning MVC using the music store examples on the www.asp.net/mvc page,
I'm learning MVC and am having trouble deciding when I should create a new
I'm learning ASP.NET MVC and bugged by one issue. In the HomeController, the Index
I'm just learning asp.net mvc and I'm trying to figure out how to move
I've been learning the new ASP.NET MVC framwork lately and I've developed a test
I'm brand new to MVC and, as a learning exercise, I'm trying to re-write
I've been working with ASP.NET MVC for the last few weeks, learning as I

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.