开发者

NHibernate + Sql Compact + IoC - Connection Managment

开发者 https://www.devze.com 2022-12-24 15:48 出处:网络
When working with NHibernate and Sql Compact in a Windows Form application I am wondering what is the best practice for managing connections. With开发者_如何学运维 SQL CE I have read that you should k

When working with NHibernate and Sql Compact in a Windows Form application I am wondering what is the best practice for managing connections. With开发者_如何学运维 SQL CE I have read that you should keep your connection open vs closing it as one would typically do with standard SQL. If that is the case and your using a IoC, would you make your repositories lifetime be singletons so they exist forever or dispose of them after you perform a "Unit of Work".

Also is there a way to determine the number of connections open to Sql CE?


In my DAL or DataService, which will have a lifetime of the entire app, I'd create and hold open a connection to the database and then let the ORM do whatever it wants for its own connection management. I would only do this in a Compact Framework app, though, where the speed of building up and tearing down the connection for each query might make a difference.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号