HomeActive Query Builder - Metadata handling and filtrationWorking with metadata in .NET versionAdding fields for objects in the Metadata Container using events

1.6. Adding fields for objects in the Metadata Container using events

Below are the sample handlers of the MetadataContainer.ItemMetadataAdding and the MetadataContainer.ItemMetadataAdded events that perform pre- and post-processing on requesting child metadata for a Table metadata item.

void MetadataContainer_ItemMetadataLoading(object sender, MetadataItem item, MetadataType loadTypes)
{
	if (item.Type == MetadataType.Table && item.Name == "Demo Table")
	{
		MetadataField pk = item.AddField("Field 1");
		pk.FieldTypeName = "int";
		pk.PrimaryKey = true;

		MetadataField f2 = item.AddField("Field 2");
		f2.FieldTypeName = "nvarchar";
		f2.Size = 30;

		item.AddField("Field 3").FieldTypeName = "datetime";
	}
}
private void MetadataContainer_ItemMetadataLoaded(object sender, MetadataItem item, MetadataType loadtypes)
{
	if (item.Type == MetadataType.Table && item.Name == "Demo Table")
	{
		foreach (MetadataField field in item.Items.Fields)
		{
			field.Name = field.Name.ToUpper();
		}
	}
}

This page was: Helpful | Not Helpful