I have a mapping question related to Table Per Type. I have following hierarchy:
- Person (maps to table person)
- A person can be a Subscriber (maps to table Subscriber)
- A person can be a Service Provider (maps to table ServiceProvider)
- A person can be {other things}
This maps to respective domain objects. The current mapping looks something like below:
public class PersonMapping : ClassMap<Models.Person>
{
public PersonMapping()
{
Table("Person");
Id(p => p.Id);
... other props
}
}
public class SubscriberMapping : SubclassMap<Models.Subscriber>
{
public SubscriberMapping()
{
Table("Subscriber");
KeyColumn("Id")
... other props
}
}
public class ProviderMapping : SubclassMap<Models.Provider>
{
public ProviderMapping()
{
Table("ServiceProvider");
KeyColumn("Id");
... other props
}
}
The problem I am facing is when a person exists but not as a Subscriber.
The behavior that we are trying to implement is:
Add Subscriber:
- Check if Person exists by <well defined criteria>
- If Person was found insert into subscriber table
- If Person was not found
- Create Person
- Insert into subscriber table
Can this behavior be achieved using mapping?
Thanks,
PG