I have base class Entity and an enheritance class say Home ,
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<Home > Homes{get;set;}
}
I want to set the CityId for Town and its children so a first try I did the following
public class DataAccessBase<T> where T : Entity
{
public int Add(T entity)
{
Type t = typeof(T);
PropertyInfo prop = t.GetProperty("CityId");
if (prop != null)
{
prop.SetValue(entity, 2);
}
}
}
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