title: Generic classes and its child
body: <p>I have base class Entity and an enheritance class say Home , </p>
  
  <pre><code>public class Home : Entity
  {
      public int CityId{get;set;}
  }
  
  public class Town : Entity 
  {
      public int  CityId {get;set}
      public Home CityHall {get;set;}
      public List&lt;Home &gt; Homes{get;set;}
  }
  </code></pre>
  
  <p>I want to set the CityId for Town and its children 
  so a first try I did the following </p>
  
  <pre><code>public class DataAccessBase&lt;T&gt; where T : Entity
  {
      public int Add(T entity)
      {
          Type t = typeof(T);
          PropertyInfo prop = t.GetProperty("CityId");
          if (prop != null)
          {
              prop.SetValue(entity, 2);
          }
      }
  }
  </code></pre>
  
  <p>this work only for the parent how to access children , I want to d othat generically simply because I have a dataaaccesslayer that insert of Database genrically </p>