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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:24:06+00:00 2026-06-09T10:24:06+00:00

I have 2 classes containg POCO entities in MVC3 public class TeamMember { public

  • 0

I have 2 classes containg POCO entities in MVC3

public class TeamMember 
{
  public DateTime JoinDate { get; set; }
  [Required]
  Public string Name{ get; set; }
} 

public class Project
{
   [Required]
   public string Name { get; set; }  
   public DateTime StartDate { get; set; }
}

I want to set the default value of TeamMember JoinDate with Project StartDate.
Can anybody pull me out of this

  • 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-09T10:24:07+00:00Added an answer on June 9, 2026 at 10:24 am

    You could do it in the controller, something like:

    if(teamMember.JoinDate == null)
    {
        teamMember.JoinDate = project.StartDate;
    }
    

    and you could add more logic if project.StartDate == null then project.StartDate = DateTime.Now.

    I’m not sure you can do this as a default in the model itself though.

    Update

    As you have it, I don’t think the Project StartDate can see the TeamMember JoinDate, I think you will need to give them a one to one relationship. I’m not sure of the exact syntax since I’m not on my work system, but something like this should work:

        public class TeamMember 
        {
          public DateTime JoinDate
          { 
              get { return this.JoinDate; }
              set { JoinDate = this.Project.StartDate; }
          }
          [Required]
          public string Name{ get; set; }
          public virtual Project Project { get; set; }
        } 
    
        public class Project
        {
           [Required]
           public string Name { get; set; }  
           public DateTime StartDate { get; set; }
        }
    

    Update 2

    Thinking about it, you need to allow JoinDate to be null or else it will throw a validation error, then you need to check to see if there is a value for it. Something more like this:

        public class TeamMember 
        {
          public DateTime? JoinDate
          { 
              get { return this.JoinDate; }
              set
              {
                  if(JoinDate == null)
                  {
                      JoinDate = this.Project.StartDate;
                  }
                  else
                  {
                      JoinDate = JoinDate;
                  }
              }
          }
          [Required]
          public string Name{ get; set; }
          public virtual Project Project { get; set; }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class: public class Chid1 : Parent{ public string var1{get;set;} public string
I have the following Entity Framework POCO classes: public class Customer { public int
I have XNA game and it contains these classes public partial class Bird :
Suppose I have classes Foo and Bar as follow: public class Foo { public
I have created a class with 3 sub classes in Java. The 3 sub
I have a class RequestDetail . There are 2 classes classA and classB derived
You may have multiple classes on an element separated by a space: <div class=header
I have generated my POCO entities using POCO Generator, I have more than 150+
This is my (simplified) problem. The classes: public class RetailExposure { public int RetailExposureId
I have a simply Class that is intended to be a simple POCO -

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.