google-code-export / otis-lib

Automatically exported from code.google.com/p/otis-lib
2 stars 0 forks source link

Can OTIS Map Collections using XML Mappings only #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
We have been using OTIS to good effect. Is it possible to define mappings to 
map elements of a collection?

Example:

<Class>

<member name="TargetArray[0]" expression="$SourceObject.m1"
<member name="TargetArray[1]" expression="$SourceObject.m2"

</Class>

Is this possible?

Original issue reported on code.google.com by sharad.y...@gmail.com on 7 Feb 2013 at 2:19

GoogleCodeExporter commented 9 years ago
Unfortunately, not. 
Actually, it can map collections, but it can't map to collection elements. 

The `name` attribute must always refer to a field/property in order to read the 
required metadata (e.g. PropertyInfo). 

A workaround is to use helper as described in XmlMappings, but the drawback is 
that you need to introduce mapping concerns into your domain (which is I guess 
the reason you would prefer XML mapping instead of metadata)

Original comment by zdeslav....@gmail.com on 7 Feb 2013 at 11:18

GoogleCodeExporter commented 9 years ago
Thanks for the quick reply.

I have one more followup question.

Is it possible to explain the syntax of mapping arrays or collections using 
XMLMappings.

Original comment by sharad.y...@gmail.com on 7 Feb 2013 at 1:59

GoogleCodeExporter commented 9 years ago
`name` is a name of collection property on target object (e.g. DTO). it can be 
an array, List<> or IList<>. `expression` is an expression evaluated on source 
object (e.g. a domain object) which results with a collection object (again an 
array or a list). See `ProjectList` in MetadataMappings
lists can be mapped to arrays and other way round. please take a look at unit 
tests (e.g. CollectionMappingTest.cs).

It is also possible to map a scalar property on target to an expression, e.g. 
map an integer property to the greatest value in the source collection. See 
`aggregate functions` in MetadataMappings

Original comment by zdeslav....@gmail.com on 7 Feb 2013 at 3:06