I'm using the Fluent automapper to map my classes and I currently have a base class containing summary information for a person and a derived class containing their full information:
interface IPersonSummary
{
string Name { get; set; }
DateTime? DOB { get; set; }
}
interface IPerson : IPersonSummary
{
string Address { get; set; }
string HairColor { get; set; }
}
public class PersonSummary : IPersonSummary
{
public string Name { get; set; }
public DateTime? DOB { get; set; }
}
public class Person : PersonSummary, IPerson
{
public string Address { get; set; }
public string HairColor { get; set; }
}
I know it's possible to use a projection to load from the database only the fields needed to populate a PersonSummary but it requires explicitly declaring each field to map, which kind of defeats the whole point of using the automapper in the first place. I also haven't been able to find out how to use a projection to create a new entry in the database, with the extra fields (i.e. Address and HairColor) getting set to their default values. I've tried providing an override to set both Person and PersonSummary to use the same table but as expected Fluent complained about it.
How should I go about mapping these classes to the same table?