Hi,
I am trying to build out a business domain model using the generated DAL (adapter model). We are keen to separate out the DAL and business tier so the business domain is being implemented as a separate class library. However, in order to improve productivity, I am inheriting entity classes and simply adding methods, properties, etc as required. So, for example, one class in by business tier might be:
public class People : PersonalEntity
{
public People(Int32 personId)
{
Id = personId;
using (DataAccessAdapter adapter = new DataAccessAdapter(true))
{
adapter.FetchEntity(this);
}
}
public People(): base()
{
}
public static EntityCollection<People> GetPeople()
{
EntityCollection<People> people = new EntityCollection<People>(new PersonalEntityFactory());
try
{
using (DataAccessAdapter adapter = new DataAccessAdapter(true))
{
adapter.FetchEntityCollection(people, null);
}
}
catch (Exception e)
{
Diagnostics.LogToFile(MethodInfo.GetCurrentMethod(), e);
throw e;
}
return people;
}
}
The trouble is, when I call something like this:
EntityCollection<People> people;
people = People.GetPeople();
...in my presentation code, I get and error “entityToAdd isn't of the right type”. I assume this is because of the inheritance. When I change GetPeople to return EntityCollection<PersonalEntity> everything is fine (apart from the class being downcast of course).
So, I am not sure if I am asking a technical question or asking for best-practice architectural advice but either way your help would be greatly appreciated.