I don't really have an issue or anything but I'm just wondering if the way I'm using NHibernate is the correct way, conform with Nhibernate best practices.
To start off I'm very new to the framework, but I really like what the possibilities are.
I'm just creating something small to test all the things that are inside of the framework.
This is my setup:
I have 3 projects. Kinda like a 3Tier model
- Core: Which basically contains my entity classes. Customer, Order etc.
- Client: Which contains the forms that the user will see
- DataBaseLogic: Which contains the Nhibernate intelligence
Now I'll show some small code samples to let you see how I'm working. I don't want to start off implementing a bad design. So please if there are any remarkt, comments, articles. Please let me know.
Core
Core for instance contains a
Customer class and a
Nhibernate mapping file.
DatabaseLogic
Here is the project where the SessionFactory gets created and of course all the other database operations.
For now the creation of the SessionFactory is quite specific to the Customer class. It's a singleton class because this is a quite expensive process. I probably should have one class that creates the SessionFactory/database and just add all the other assemblies to it, right?
Here is the code for the
SessionFactory
Then I created database opetation classes for each entity in the class the CRUD operations etc happen. Here is an example piece of code on
getting a list of customers and deleting a customer. I know that I didn't implement a try/catch block. Mind the fact that this is just for testing purposes.
Client
Here are the forms that the user sees and on the button events, I call the appropreate methods from the DatabaseLogic layer. I know that is maybe better to implement a BusinessLogic layer, but I don't really have and business rules that need be checked on and I don't like the idea of an empty dispatching layer..so this is the reason it's not used for now.
The following pieces of code show how I
retrieve a list of clients and how I add a new one from the client form.
Thank you for reading up to this part. If anyone thinks, why did he do this or that. Maybe he should do it better this way to gain better performance in this part..please..tell me.
Thanks again,
Kind regards,
Sven