Considerations for Custom Data Generators
You can extend the data generation capabilities of Visual Studio Team Edition for Database Professionals by creating custom data generators or by extending standard data generators. If you have a business rule that the standard data generators cannot satisfy, you can create a custom data generator. For more information, see Overview of Generating Data. Before you create a custom data generator, you should consider the following issues.
Data Generator Naming
When you create a custom data generator, you can control the name that appears in the user interface for that custom data generator. You should avoid giving the same name to multiple data generators because users cannot easily distinguish between them.
Naming when you use the Declarative API
If you do not declare a designer for use with your custom data generator, the class name of the data generator appears as the display name when the DefaultDistributionDesigner is created. You can apply the following attribute to your custom data generator class to specify the name for the generator that appears in the user interface for the custom data generator:
[System.ComponentModel.DisplayName("YourGeneratorName")]
Naming when you use the Base API
If you create a custom designer, the value that is returned by the Name property of the designer appears in the user interface for the custom data generator. If you derive your custom designer from DefaultDistributionDesigner, the DisplayName attribute is used. If you instead derive from IGeneratorDesigner, the DisplayName attribute is ignored. To specify the DisplayName attribute for your data generator, you must add the following attribute:
[System.ComponentModel.DisplayName("YourGeneratorName")]
Specifying a Custom Data Generator as the Default Data Generator for a SQL Data Type
You can assign a custom data generator as the default data generator for a SQL data type, but some restrictions apply.
You can assign a custom data generator to any SQL data type that cannot have a unique constraint. For example, you can assign a custom data generator to the Image data type.
You can assign a custom data generator that has no filter attribute to any SQL data type.
You can assign a custom data generator that has a filter attribute to a SQL data type that can have a unique constraint only if the custom data generator can produce unique values. To designate this kind of generator, apply the following attribute to the custom data generator class:
<GeneratorStyles(DesignerStyles:=GeneratorDesignerStyles.CanProduceUniqueValues)> _ Public Class TestGenerator Inherits Generator End Class
[GeneratorStyles(DesignerStyles = GeneratorDesignerStyles.CanProduceUniqueValues)] public class TestGenerator:Generator { }
Custom Designers
By default, a custom data generator will use the default designer. If you want to use a custom designer with your custom data generator, you must specify an additional attribute on the custom data generator class:
<Generator(GetType(CustomDesignerType))> _
Public Class TestGenerator
Inherits Generator
End Class
[Generator(typeof(CustomDesignerType))]
public class TestGenerator:Generator
{
}
Auto-assigned Input Properties
If you mark one or more input properties for your custom data generator with the AutoAssignedInput attribute, you should also make those properties read-only. Most properties that you mark as auto-assigned will have their values reset when you open the data generation plan. For example, the Collation, Data Type, MaxLength, Nullable, and RowsToGenerate properties are all reset when they are marked as auto-assigned. The Unique, Seed, and PercentageNull properties are not reset. By marking the properties whose values will be reset as read-only, you help avoid confusing the user of your custom data generator.
See Also
Tasks
How to: Create Custom Data Generators
Walkthrough: Creating a Custom Data Generator