Skip to content

Flattening of complex (object) properties of an entity #38

Open
@satano

Description

This is detailed info about Support for complex entities, whose properties are another objects from issue #8.

The goal

We want to load (and save) from database entities with complex properties. Complex property is a property which is another object. In its simplest form, say we have this entity Invoice:

public class Invoice
{
    int Id { get; set; }
    string InvoiceNumber { get; set; }
    Address Supplier{ get; } = new Address();
    Address Purchaser { get; } = new Address();
}

public class Address
{
    public string Street { get; set; }
    public string City { get; set; }
    public string Country{ get; set; }
}

And we want to automatically map it to table with these columns:

  • Id
  • InvoiceNumber
  • SupplierStreet
  • SupplierCity
  • SupplierCountry
  • PurchaserStreet
  • PurchaserCity
  • PurchaserCountry

What/how should work

  • Complex properties with injector set must not be flattened.
  • Column name will be defined as concatenated names of properties:
    Supplier.Street -> SupplierStreet
  • Deep flattening of properties:
    Invoice.Supplier.Address.Street -> SupplierAddressStreet
  • Setting specific column name for nested property:
    .Property(p => p.Supplier.Address.Street).HasColumnName("SupplierStreet")
  • Complex properties can be readonly ({ get; }) or read/write ({ get; set; }).
    • If the property is null, instance should be created automatically if it is possible (property is r/w and property's type has parameterless constructor).
  • Can set nested properties as not mapped:
    .Property(p => p.Supplier.Country).NoMap()
  • Can use injectors for nested properties:
    .Property(p => p.Supplier.Country).InjectValue(...)
  • Update readme.

Other considerations

  • Should flattening work automatically and be turned off if not wanted, or vice versa?
  • We will support only fluent configurations for this (no attributes).
  • Can we make whole attribute configuration obsolete?

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions