title: How to implement a DateTime entity property to set always DateTime.Now
body: <p>I've read a bunch about auto implemented properties but I still don't quite get it. I have and entity:</p>
  
  <pre><code> public class News
      {
          public int NewsId { get; set; }
          public string Title { get; set; }
          public string Content { get; set; }
          public DateTime Date { get; set; }
      }
  </code></pre>
  
  <p>Now I don't want the user to set date himself every time a new entity of <code>News</code> type is created. I want the record to be saved automatically with the datetime it's created. Thinking about it I suggest that it's enough to just modify the <code>set</code> for my property to something like :</p>
  
  <pre><code>public DateTime Date 
  {
    get;
    set
    {
      Date = DateTime.Now;
    }
  }
  </code></pre>
  
  <p>But reading about the topic I saw that the standard way is to create private variable and use it instead in the implementation. That's where I get a little bit lost.</p>
  
  <pre><code>private DateTime _date = null;
  public DateTime Date
  { 
  </code></pre>
  
  <p>Well I'm not sure for the getter and setter implementations. It seems reasonable to have something like : <code>set { _date = DateTime.Now;}</code> and I have no idea how to deal with the <code>get</code> part since I want this data to be fetched from the database so something like : <code>get {return _date;} doesn't make much sense to me even though almost every example with auto implemented</code>set` returns the private variable. But I think that if the property is an entity this is not making a lot of sense.</p>