Data Source Kind

eric.peach posted this 22 September 2013

We are creating mail merge POC in our project using the toolkit. We are using entity framework to load the data from the database and we plan to use the entity objects to populate the templates.

My question is: Is there any benefit using XML data sources over .NET objects? We already have our entity object ready but we could also easily generate XML from them. I would just like to know what are pros and cons using the first or the latter one.

Last edited 04 October 2013

2 Posts
2 Points
Order By: Standard | Newest | Votes
jles posted this 23 September 2013

Hi Eric,

Document generation functionality can be seen as separate UI layer in an application and could have its own "view models". In your case this means that your EF entities are models that would be the source for your "document generation view models". Creating another tier of data objects (VM) has the same reason as creating them for rendering Views. Your models simply do not always have all the properties ready for data binding and this is why you need a specially shaped data objects are suitable for data-binding in Views. On the other side creating another set/layer of such objects (including mappings) is (I think) mostly seen as overhead and people rather use their Data Access (EF) objects directly by extending them with calculated properties or handling the Element.Initialize event.

Yes, another option is to use XML. Here are the summarized differences:
- XML: If your data is represented by .NET objects than there is additional effort and complexity to convert them into XML. On the other side, the binding language (when editing templates) is XPath which means that you can write complex XPath expressions if you want and this way achieve data shaping directly in templates.
- .NET Objects: You can mostly use your existing DTOs/busines objects/entities as data sources directly. But the binding language is only limited to memer (property or field) selection and there is no way to do data shaping inside templates. To compensate this inability you have to resort to class extensions, creation of specific set of classes or handling the Element.Initialize event.
- DTS Objects: Same pros and cons as .NET objects except they are more simple than .NET objects.

I mostly prefer .NET objects (or even DTS objects) over XML because: - there usually already are existing .NET objects to use or they can easily be created using your favorite language (C#, VB.NET) - .NET schema has cleaner semantics than XML schema for distinguishing between single objects/values and collections - which is vary important when creating templates.


Last edited 04 October 2013

81 Posts
159 Points
eric.peach posted this 24 September 2013

Thank you for the quick and comprehensive explanation. This really helps!

regards, eric

Last edited 04 October 2013

2 Posts
2 Points

Our 49 members have posted 180 times in 53 discussions