Advise on setting up seed data using nhibernate during development (not test suite)
How s开发者_如何学Chould one go about setting up seed data while developing an nhibernate web application? (It's Mvc)
Should I just create a method and have it fire during application load (when it debug mode), and simply comment it out when I don't need it?
or is there a better way?
I suggest looking at something like AutoPoco.
AutoPoco replaces manually written object mothers/test data builders with a fluent interface and an easy way to generate a large amount of readable test data. By default, no manual set-up is required, conventions can then be written against the names/types of property or manual configuration can be used against specific objects.
The primary use cases are
- Creating single, valid objects for unit tests in a standard manner across all tests
- Creating large amounts of valid test data for database population
This is not tied directly to NHibernate - you could in theory combine it with any data-layer that can persist POCO's.
I'd avoid adding code to Application_Start though - that sounds like a recipe for accidentally trashing your production database. You'd be better off creating a simple console application that you can run whenever you want to reseed your database.
精彩评论