-
Notifications
You must be signed in to change notification settings - Fork 22
Entities
Entities are complex types with an entity flag, distinguishable from other entities by one or more members configured as key members. At least one member must act as key for the entity to be valid.
An entity has a set of members that can be primitives, collections or other entities. A recursive call to map is done for entity and collection of entity members configured as associations. Values of members flagged as key are used to determine if a DTO or source entity and a target entity instances represents the same real thing and should be merged.
Members can be individually configured to be excluded from the mapping operation, mapped to a different member or even apply some logic when a value is get or set, in same way it is done for complexes.
For EntityFramework, all the entities along with their keys defined in the DbContext are automatically flagged, so no configuration is actually needed. However, for testing, samples or extensions, standalone class (i.e.: not a part of a DbContext) can be configured as entities.
[Entity]
public class Invoice
{
[Key]
public Guid Id { get;set; }
}
services.AddDbContext<MainDbContext>(dbContextOptions =>
{
...
dbContextOptions.UseMapping(mappingOptions => {
mappingOptions.Default(profileOptions => {
profileOptions.Type<Invoice>().Entity()
.Member(i => i.Id).Key();
});
});
});