The MailMerge class has three methods to start the merge process. This article explains when to use which method.

Merge

The method Merge has four implementations and is basically used when merging a template with a DataSet or a data source configuration file. When merging with a DataSet, the master table is passed in the mergeData parameter.

The master table is used as the base table and all related tables are automatically used for merge blocks and prefixed merge field names.

public void Merge(System.Data.DataTable mergeData, bool append);
public void Merge(System.Data.DataTable mergeData);
public void Merge(bool append);
public void Merge();
view raw tx.cs hosted with ❤ by GitHub

MergeObject

MergeObject has been introduced in version X13 (23.0) to merge all types of business objects of type IEnumerable. While MergeObjects (plural) merges a collection of IEnumerable objects, MergeObject merges a single instance of an arbitrary type into the loaded document template.

MailMerge interprets all public properties of the object as table columns and child tables. The object type is analyzed using .NET reflection and used as the basis of the table structure. Nested object types are used for merge blocks and prefixed merge fields.

public void MergeObject(object mergeData);
view raw tx.cs hosted with ❤ by GitHub

MergeObjects

This method merges a collection of type IEnumerable into the template. For each object in the collection, a new document is created or appended to the resulting document.

public void MergeObjects(System.Collections.IEnumerable mergeData, bool append);
public void MergeObjects(System.Collections.IEnumerable mergeData);
view raw tx.cs hosted with ❤ by GitHub