调试时检查数据库
我正在尝试使用 nhibernate 映射进行一些级联选项,并进行单元测试,我想使用一个工具来检查数据库的状态。 我希望我可以使用 linqpad 来执行此操作,但在调试器中连接似乎挂起。 不久前我看过一个演示,其中 SSMS 用于在调试期间检查数据库,所以我想知道我是否应该能够以某种方式使用 linqpad 或者我是否需要不同的工具(我还没有安装我的笔记本电脑上有 SSMS,并且更喜欢重量更轻的东西)。
与 linqpad 无关,我这样做的动机是我不确定我在单元测试中验证的数据库状态是来自数据库还是来自 nhibernate 的缓存? 如果在断言之前调用 Session.Flush() ,这是否意味着断言中的提取保证来自数据库?
干杯, 贝里尔
I am trying out some cascade options with nhibernate mapping and have a unit test where I'd like to use a tool to inspect the state of the database. I was hoping I could use linqpad to do this, but the connection seems hung while in the debugger. I'd seen a demo not to long ago where SSMS was being used to inspect the db during a debug, so I'm wondering if I should be able to somehow use linqpad or if I need a different tool (I haven't installed SSMS on my laptop and would prefer something more light weight).
Unrelated to linqpad, my motivation for doing this is I am not sure if the db state I'm validating in a unit test is from the db or from nhibernate's cache? If Session.Flush() is called before the the assert, does that mean a fetch in an assert is guaranteed to be coming from the db?
Cheers,
Berryl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于问题的第二部分 - 是的,在任何类型的提取之前调用 session.flush() 会将所有内容推送到数据库。 您也可以这样做:
希望有帮助。
To the second part of your question - Yes, calling session.flush() before any kind of fetch will push everything out to the DB. You could also do:
hope that helps.
SQL Profiler(SSMS 中的“工具”>“SQL Server 配置文件”)或 NHProf 将帮助您监视发送到数据库的命令。
SQL Profiler (Tools > SQL Server Profile from SSMS) or NHProf will help you monitor commands sent to the database.
您可以使用 HSQLDB 中包含的 DatabaseManagerSwing 类,它会打开一个 Swing 应用程序,允许您浏览数据库中的对象还可以运行查询。 通过向其传递一个打开的连接,您可以查看连接所在事务中数据库的状态。
You could use the DatabaseManagerSwing class included in HSQLDB, it opens a Swing application that allows you to browse the objects in a db and also to run queries. Passing to it an open connection allows you to see the state of the database in the transaction the connection is in.