views:

395

answers:

1

I'm just getting started with Visual Studio Database projects and loving the data generation plans I can create with it. However, in one of my projects I need to populate a lookup table with specific values. Since a foreign-key relationship exists between the lookup table and another table, I can't remove the lookup table from the data generation plan without removing the other table from the plan. But then I can't generate any data for the other table.

How can I either a) specify the exact data I want the generator to use when adding data to the lookup table, or b) have the generator not add new values to the table but instead use values that already exist?

Thanks!

+1  A: 

Here's my take on Consistent Data Generation in Visual Studio 2008

The data generation tool in Visual Studio 2008 Data Edition is a great tool for populating your database with meaningless information to use in your unit tests, but when it comes time to do integration testing it's often important to have your data generation plan recreate a consistent dataset in key tables (like the lookup tables used in foreign keys which are often mirrored as Enums in your C# or VB.Net solutions). Fortunately, the data generation tool includes the sequential data-bound generator. This generator selects records from the specified data source and uses the results to populate your table.

So how do we make use of this? In our database solutions, we include two databases - the actual database we're working on, and a datageneration database. For the tables we need to consistenly populate, we duplicate the schema & table in the datageneration database (minus any indexes/keys/constraints/triggers, etc.), and then use the post-deployment script for that database to create the desired records. To reduce duplication of the populate scripts, the post-deployment script for the real database points to the datagenration populate script by a relative path. This also means that these tables will have the same records in them whether you have just deployed the database, or just run the data generation plan - which makes life easier for everyone on the team.

Full details here

Peter LaComb Jr.