Immutable design with an ORM: How are sessions managed?

Posted by Programmin Tool on Programmers See other posts from Programmers or by Programmin Tool
Published on 2012-01-11T00:37:49Z Indexed on 2012/11/19 5:26 UTC
Read the original article Hit count: 243

If I were to make a site with a mutable language like C# and use NHibernate, I would normally approach sessions with the idea of making them as create only when needed and dispose at request end. This has helped with keeping a session for multiple transactions by a user but keep it from staying open too long where the state might be corrupted.

In an immutable system, like F#, I would think I shouldn't do this because it supposes that a single session could be updated constantly by any number of inserts/updates/deletes/ect... I'm not against the "using" solution since I would think that connecting pooling will help cut down on the cost of connecting every time, but I don't know if all database systems do connection pooling. It just seems like there should be a better way that doesn't compromise the immutability goal.

Should I just do a simple "using" block per transaction or is there a better pattern for this?

© Programmers or respective owner

Related posts about database

Related posts about functional-programming