title: Creating a Base Class for all entities in Entity Framework 5 in DB first approach
body: <p>I have few properties like CreatedDate, ModifiedDate, VersionNo on every table. I need to change/ add values for these properties every time I modify the entity. I thought I could create a Base class with these Properties and let the Entities derive from this Base class and during SavingChanges based on ObjectState I could change the Values and Save, that way my audit entries will be isolated from the entity and the thing will be abstracted. But since I am new to Entity Framework , I am finding it difficult to understand how will I handle the mappings, etc.. </p>
  
  <p>If anyone can suggest ideas for implementing this, that would be really helpful.
  Repository code is like below:</p>
  
  <pre><code>public class GeneralRepository&lt;T&gt; : IRepository&lt;T&gt; where T : class
  {
      private ObjectSet&lt;T&gt; _set;
      private ObjectContext _context;
  
  
      public GeneralRepository(ObjectContext context)
      {
          if (context == null) throw new ArgumentNullException("context");
          _context = context;                 // sets the context
          _set = context.CreateObjectSet&lt;T&gt;(); // returns the Object Set
      }
  
  
      #region Methods to override to work with ObjectGraphs .
  
      /// &lt;summary&gt;
      /// To insert data from entity into a table.
      /// &lt;/summary&gt;
      /// &lt;param name="entity"&gt;&lt;/param&gt;
      public virtual void Insert(T entity)
      {
          if (entity == null) throw new ArgumentNullException("entity");
          _set.AddObject(entity);
      }
  
  
      /// &lt;summary&gt;
      /// To delete entity from a table. 
      /// &lt;/summary&gt;
      /// &lt;param name="entity"&gt;&lt;/param&gt;
      public virtual void Delete(T entity)
      {
          if (entity == null) throw new ArgumentNullException("entity");
          _set.Attach(entity);
          _set.DeleteObject(entity);
      }
  
  
      /// &lt;summary&gt;
      /// To update Entity into the table
      /// &lt;/summary&gt;
      /// &lt;param name="entity"&gt;&lt;/param&gt;
      public virtual void Update(T entity)
      {
          if (entity == null) throw new ArgumentNullException("entity");
          _set.Attach(entity);
          _context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
      }
  
      /// &lt;summary&gt;
      /// To get th entire table contents
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public IQueryable&lt;T&gt; GetAll()
      {
          return _set;
      }
  </code></pre>
  
  <p>}</p>