-
Notifications
You must be signed in to change notification settings - Fork 5
Tutorial Part 4
Auswöger Matthias edited this page May 12, 2021
·
1 revision
In the following tutorial we take the result of Part 3 and improve it.
We will extract a common member of our entities to show how to use inheritance with entity classes.
All our entities do have an Id property, and we will make a base class that will contain that property and let all the entity classes inherit that property.
Add a new Entity class that look like this:
public abstract class Entity
{
[Mapping(FieldName="Id"), IsPrimaryKey]
public abstract int Id { get; }
}Change all the entities like it's done here for the Customer entity.
Remove the Id property of the entities and derive them all from the Entity class, so that the class below:
public abstract class Customer
{
[Mapping(FieldName="Id"), IsPrimaryKey]
public abstract int Id { get; }
[Mapping(FieldName = "FirstName")]
public abstract string FirstName { get; set; }looks like this:
public abstract class Customer : Entity
{
[Mapping(FieldName = "FirstName")]
public abstract string FirstName { get; set; }After this is done, everything works as before, just without the need of adding the Id property to every entity class.
Checkout the full example here.