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:
客户端代码应该与干净的对象一起使用,没有数据库知识。使用我们的自定义框架时,客户端代码看起来像:
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 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.
根据我现有的知识,我看到这些选择:
- 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.
你会提什么建议?
编辑:
谢谢Craig详细的回答。我认为如果我提供关于我们自定义框架的更多细节,将有更多帮助。我正在寻找类似的东西。以下是我们自定义框架的工作方式:
- 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.
为了与我们的框架兼容,数据库必须满足以下标准:
- 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.
我们现在想要支持的是:
- 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.
我希望现在我要寻找的更清晰了。