I'm a .NET developer by day, but have been working with Rails and Merb for the past year on my own side projects, so when it comes to MVC and ORMs, I'm more used to them and using ActiveRecord and DataMapper.
I'm getting started with ASP.NET MVC, and I like what I see in NHibernate and Fluent NHibernate, but looking for a little bit more around how to best handle the unit of work or repository type model.
I'd like something that is not huge on architecture. I've seen some projects like S#arp Architecture, but it looks kind of bloated.
All I am really after is a simple way to manage connections and handling data retrieval/storage. A simple guide or sample application would even suffice.
The unit of work class serves one purpose: to make sure that when you use multiple repositories, they share a single database context. That way, when a unit of work is complete you can call the SaveChanges method on that instance of the context and be assured that all related changes will be coordinated.
The Unit of Work is a type of business transaction, and it will aggregate all Repository transactions (CRUD) into a single transaction. Only one commit will be made for all modifications. If any transaction fails to assure data integrity, it will be rolled back.
Not necessarily. EF already provides the unit of work pattern for you. The only reason to still have a unit of work is if you: want to include non-EF-datasources in an atomic data operation.
Repository Pattern is used to create an abstraction layer between data access layer and business logic layer of an application. Repository directly communicates with data access layer [DAL] and gets the data and provides it to business logic layer [BAL].
There are a few components you can use for easy Unit of Work implementations:
As for sample projects, here is one for Burrow. I am using Burrow for a project right now and it's working fine for me. Although I don't use them, there are repository classes that use the unit of work session management, so it is really easy to get going with it. I also use Fluent NHibernate and it's straightforward to get everything working together.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With