简体   繁体   English

建议在开发过程中使用nhibernate设置种子数据(非测试套件)

[英]Advise on setting up seed data using nhibernate during development (not test suite)

How should one go about setting up seed data while developing an nhibernate web application? 开发nhibernate Web应用程序时应该如何设置种子数据? (It's Mvc) (是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的东西

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. AutoPoco凭借流畅的界面和生成大量可读测试数据的简便方法,取代了手动编写的对象母体/测试数据生成器。 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. 这并不直接与NHibernate绑定-从理论上讲,您可以将其与可以保留POCO的任何数据层结合使用。

I'd avoid adding code to Application_Start though - that sounds like a recipe for accidentally trashing your production database. 不过,我会避免向Application_Start添加代码-听起来像是无意间破坏了生产数据库的秘诀。 You'd be better off creating a simple console application that you can run whenever you want to reseed your database. 您最好创建一个简单的控制台应用程序,该应用程序可以在您希望重新设定数据库的种子时运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM