So we started using Gentle, and we've been generally pretty happy with it as basic CRUD layer. Its much easier to use than NHybernate (and I'm a bit concerned now that Hybernate is owned by JBOSS that the .NET support from a java company may not be there long term) and gives you very simple objects that can be easily persisted.
You can use the framework and generate your own classes to represent tables, but the easier way is to MyGeneration's Gentle.NET template and generate them automatically. You can simply point the template at your database and it will generate a one to one class for each table.
The best part about Gentle.NET is how easy it is to manage persistance in code. To create an object, you just create the object and set its properties. To persist it to the database, you simply call the Persist method on the object. If you want transaction support, you create a transaction object and pass in the object you want to persist and then either commit or rollback your transaction at the end. All very simple and fast to build up especially if you have an existing database schema. For doing basic inserts, deletes and fetches of lists of objects its solid, fast and simple and fast to code.
Where Gentle.NET really falls flat is on querying. Like most O/R mapping layers, its key weakness is when you have to do complex joins across a number of parent/child relationships. It takes a lot of code and lot of SQL calls to do these types of joins.
For example, I'm doing some event tables that have parent child relationships that look like this:
User -> Campaign -> Event -> GiftEvent.
Creating these in the first place is simple. Simply create the objects and persist them. In addition, if you start with the User object and move down Gentle.NET provides methods for getting children and parent lists pretty easily. So you can get all the campaigns that belong to users, all the events that belong to campaign, etc.
Where it gets tricky as with most O/R mapping layers is if you want all the GiftEvents for a particular user. In a SQL statement, this is really easy - a basic join of the four tables and you're done. But in Gentle.NET this is really tough for it to handle. The framework has a SQLBuilder class which is supposed to allow for loading up of arbitrary SQL statements into objects but the documentation for it is non-existent and I couldn't find any good examples on the net to show how this could work.
In addition, the only solution to support this at the database level is to generate a view - Gentle.NET doesn't support mapping to stored procedures.
So for these types of queries, using the Microsoft Enterprise Library to create a command object, execute a stored procedure or query and then read through the reader is easier in a pinch. In addition, you could combine the two, e.g. use traditional datasets and then populate gentle objects with the results. But its a pretty glaring weakness in an otherwise pretty good little library.
There is a version 2.0 in development but like many open-source projects it seems to be in perpetual development mode with no projected release date.
One other issue we ran into: Gentle generally provides lists of objects in non-generic lists but the new ASP.NET ObjectDataSource expects a generic list. There is a solution to this problem - if you create the generic list before hand and pass it in, Gentle will fill it for you.
So to use their example if you have code that looks like this:
static public IList ListAll{
get {
return Broker.RetrieveList( typeof(User) );
}
}
you can change it to be:
static public IList
get{
List
return Broker.RetrieveList( typeof(User), list );
}
and this will provide back a generic list which the ObjectDataSource can handle quite nicely and will allow you to bind to your data bound controls.
No comments:
Post a Comment