Quantcast
Channel: glue Wiki & Documentation Rss Feed
Viewing all articles
Browse latest Browse all 20

Updated Wiki: Nested mapping and Flattening

$
0
0
Given we have these classes:

publicclass GuiPerson
{
    public String Name { get; set; }
    public GuiAddress Address { get; set; }
}

publicclass GuiAddress
{
    public String City { get; set; }
}

publicclass DomainPerson
{
    public String Name { get; set; }
    public DomainAddress Address { get; set; }
}

publicclass DomainAddress
{
    public String City { get; set; }
}

Nested mapping

A nested mapping would be the mapping between DomainPersons Address-property and the GuiPersons Address-property. There are two ways of handling this:

Simplified nested mapping

As of version 0.3.1 of Glue, you can now simply write a mapping between the City-properties like this:

mapping.Relate(domain => domain.Address.City, gui => gui.Address.City);

When using simplified nested mapping, please note:
  • Although equal names, nested properties like City will not autorelate. Autorelate will only work on root properties.
  • Relationsverifications will not check if all properties on all nested types are related. In this case the RelationVerification would check if all the properties on GuiPerson/DomainPerson is related, but not on DomainAddress or GuiAddress.
  • Mapperverification will work as normal and test all relations added, even if they are nested.

Nested mapping with a separately defined mapping

There is also a possibility to define the mapping between City to add a mapping between Address to our mapping. There might be several reasons for doing this. For instance if you already have a defined mapping between DomainAddress and GuiAddress (you use it in other places). Or if you want to run a relationsverification on all nested properties, then you need a separate mapping that you can run it on.

Here is how you do it: Nested mapping

Flattening

Simplified nested mapping of flattened relations works just the same way as described above

If you want to define a flattening with a separately defined mapping, here's how: Flattening

Example

Here is a complete example of a mapping using simplified nested mapping: Flattening a large structure
You can also map this with explicit nested mappings, here's how: Flattening large structure with explicit nested mappings

Viewing all articles
Browse latest Browse all 20

Trending Articles