57.3. Data Generation

As well as versioning the schema, you might want a way to generate data for testing purposes. To do this, you need to add a Data Generation Plan. If you right-click the Offline Schema project under the Add menu, you will find the option for Data Generation Plan. By default all the tables on the schema will be selected, but you can override these settings. In the top section of Figure 57-4 only the Products table is checked. The Categories and Suppliers tables are automatically added (darkened checkboxes) because of the Foreign Key between Products and Suppliers and Products and Categories.

Keep in mind these generation plans are only for development and testing purposes. Don't run them on production servers.

Figure 57.4. Figure 57-4

From the Data Data Generator menu you can open the Column Details and Preview Data Generation windows.

In the plan, you can select the ratio between Related Columns; for example, in Figure 57-4 we are specifying to have 10 products for each supplier (10:1).

In the Column Details window, all columns are selected except for the SupplierID, which is an identity column. You can deselect columns as long as they have either a Default value or allow nulls. In the properties window you can specify the percentage of nulls to be generated.

For each column you can also specify the type of generator to use. By default a generator will be selected depending on the data type, or in case a column is a foreign key, the values will come from the related table's primary keys. You can use other generators. In the example in Figure 57-4, for the ContactName on the Suppliers table we used a regular expression to mix first names and last names. Another option would be to use a Data Bound Generator. In that case, you would need to specify a connection string and a select query to get the values to insert. You could also create a Custom Generator and implement your own logic simply by implementing a base class and registering your assembly as a Customer Generator. For more information see "Creating Custom Generators" on MSDN.

To run the Data Generation Plan simply select Generate Data from the Data Data Generator menu. Remember to run this plan only on a development or testing database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.255.187