gpt4 book ai didi

asp.net-mvc - 在开发期间使用 nhibernate 设置种子数据的建议(不是测试套件)

转载 作者:行者123 更新时间:2023-12-04 08:56:01 26 4
gpt4 key购买 nike

在开发 nhibernate Web 应用程序时应该如何设置种子数据? (这是 Mvc)

我是否应该只创建一个方法并在应用程序加载期间(在 Debug模式下)触发它,并在我不需要它时简单地将其注释掉?

或者,还有更好的方法?

最佳答案

我建议查看类似 AutoPoco 的内容.

AutoPoco replaces manually written object mothers/test data builderswith a fluent interface and an easy way to generate a large amount ofreadable test data. By default, no manual set-up is required,conventions can then be written against the names/types of property ormanual 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

这与 NHibernate 没有直接联系——理论上你可以将它与任何可以持久化 POCO 的数据层结合起来。
不过,我会避免向 Application_Start 添加代码 - 这听起来像是意外破坏生产数据库的秘诀。您最好创建一个简单的控制台应用程序,只要您想重新设置数据库,就可以运行该应用程序。

关于asp.net-mvc - 在开发期间使用 nhibernate 设置种子数据的建议(不是测试套件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7700765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com