I am writing an application in which we will need to extend the base object to several different things (for example, an employee, a car, etc.). The design is such that there is an Entity table and a second table with specific type values, for example, an employee will have an identification number, but the vehicle will have a registration number.
I inherited from a class object generated in the data context, but I had problems with casting in my repository. What is the right way to do this?
public class cAccountEmployee : cAccountEntity
{
public string id_number
{
get
{
try
{
return this.cAccountEntityValues.Single(e => e.type == 1).value;
}
catch (Exception)
{
return "";
}
}
set
{
try
{
this.cAccountEntityValues.Single(e => e.type == 1).value = value;
}
catch (Exception)
{
this.cAccountEntityValues.Add(new cAccountEntityValue()
{
accountentity_id = this.id,
cAccountEntity = this,
type = 1,
value = value
});
}
}
}
}
Then in my repository (nothing is inherited)
public IEnumerable<cAccountEmployee> All(int accountholder_id)
{
return db.cAccountEntities.Where(e => e.accountholder_id == accountholder_id).OrderBy(a => a.name).Cast<cAccountEmployee>();
}
public cAccountEmployee Single(int id)
{
return db.cAccountEntities.Single(a => a.id == id) as cAccountEmployee;
}
, null. , ? Linq Employee, db, ?