I'm trying to decide on the best strategy for accessing the database. I understand that this is a generic question and there's no a single good answer, but I will provide some guidelines on what I'm looking for. The last few years we have been using our own persistence framework, that although limited has served as well. However it needs some major improvements and I'm wondering if I should go that way or use one of the existing frameworks. The criteria that I'm looking for, in order of importance are:
Client code should work with clean objects, width no database knowledge. When using our custom framework the client code looks like:
SessionManager session = new SessionManager(); Order order = session.CreateEntity(); order.Date = DateTime.Now; // Set other properties OrderDetail detail = order.AddOrderDetail(); detail.Product = product; // Other properties
// Commit all changes now session.Commit();
Should as simple as possible and not "too flexible". We need a single way to do most things.
- Should have good support for object-oriented programming. Should handle one-to-many and many-to-many relations, should handle inheritance, support for lazy loading.
- Configuration is preferred to be XML based.
With my current knowledge I see these options:
- Improve our current framework - Problem is that it needs a good deal of effort.
- ADO.NET Entity Framework - Don't have a good understanding, but seems too complicated and has bad reviews.
- LINQ to SQL - Does not have good handling of object-oriented practices.
- nHibernate - Seems a good option, but some users report too many archaic errors.
- SubSonic - From a short introduction, it seems too flexible. I do not want that.
What will you suggest?
EDIT:
Thank you Craig for the elaborate answer. I think it will help more if I give more details about our custom framework. I'm looking for something similar. This is how our custom framework works:
- It is based on DataSets, so the first thing you do is configure the DataSets and write queries you need there.
- You create a XML configuration file that specifies how DataSet tables map to objects and also specify associations between them (support for all types of associations). 3.A custom tool parse the XML configuration and generate the necessary code. 4.Generated classes inherit from a common base class.
To be compatible with our framework the database must meet these criteria:
- Each table should have a single column as primary key.
- All tables must have a primary key of the same data type generated on the client.
- To handle inheritance only single table inheritance is supported. Also the XML file, almost always offers a single way to achieve something.
What we want to support now is:
- Remove the dependency from DataSets. SQL code should be generated automatically but the framework should NOT generate the schema. I want to manually control the DB schema.
- More robust support for inheritance hierarchies.
- Optional integration with LINQ.
I hope it is clearer now what I'm looking for.