OR Mapping vs DAL

This is an open forum for any mojoPortal topics that don't fall into the other categories.

This thread is closed to new posts. You must sign in to post in the forums.
11/14/2004 8:38:29 PM
Gravatar
Total Posts 3

OR Mapping vs DAL

Hi All,

first, sorry for the test post...

I am looking around for a good C# CMS, to use and contribute to for a while. What puzzles me is that all solutions are putting great efforts in writing different DALs for different DBs although there are great OR - Mapping solutions which free you of these tasks and leave you working with what a OO-Devloper should deal with: Objects.

Gentle Persistence Framework and nHibernate are good examples on how one save development efforts for persistence tasks.

Any thoughts?
11/15/2004 12:27:40 AM
Gravatar
Total Posts 3

Re: OR Mapping vs DAL

Hi Joe

There are a lot of different Mappers out there. Have a look at
http://www.theserverside.net/news/thread.tss?thread_id=29914
for an pretty nice list.
i personally prefer mapper that:

- can be used on poco (plain old clr object) objects so you haven't to break your design.
- let me define the mappings in an xml - file.
- work with different databases (MS SQL, MySQL at least)
- are opensource

i actually know (used them a little bit):

- NPersist (http://www.npersist.com)
-DAO.NET (http://dao.evolvesoftware.ch)  --> There is a new Version coming out (soon)

I'm in the process of converting NPersist  to mono and  it nearly works now (i'm running the win compiled bytecode on the mono enviroment since NPersist is coded in VB.NET and the mbas compiler isn't ready yet.)

After that I'll do the same with DAO.NET which should be a breeze to convert. (maybe it runs out of the box...)

After that I'll use both within the mono enviroment and decide for myself which one fits better.

imho choosing an mapper depends a lot on personal preference. would be intereseting to hear some more voices on this topic

greets

Phil
11/15/2004 8:55:50 AM
Gravatar
Total Posts 18439

Re: OR Mapping vs DAL

I respect your opinion and appreciate your input but I disagree about OR mapping.  I have read a bit about OR mapping and it certainly is getting a lot of buzz in the press lately but myself I think it is a bad idea and definitely will not be using it in mojoPortal. Instead I use a code generator to generate some of my code. I can generate most of the code for data access to support additional dbs using a code generator by writing scripts for the specific db so the time saving aspect of OR mapping is not much benefit to me because I already have a way to reduce development time for data access code significantly. I use CodeSmith Studio to write my generation scripts that write the basic CRUD code and then I modify the generated code when I need something other than basic CRUD. This has saved me a lot of time in creating data access code for MS SQL and MySQL and I may even support Postgre SQL in the future. By not using OR mapping I believe my code is cleaner, performs better, and is easier to understand than would be the case with any OR mapping. Hibernate just came out with a 400 page book on using it which to me is a clear indicator of the amount of complexity it adds to the source code for a project. I know there are a lot of different ones out there. IBATIS is one I've heard people recommend quite a bit in the Rainbow Portal mailing list. They are looking into using OR Mapping in the near future so you might want to checkout http://www.rainbowportal.net its a mature CMS written in C# and progress has been made in getting it to run under mono. Rainbow has a lot more features than mojoPortal because they've been working on it for several years now where I am just getting started.

Another reason I think OR Mapping is a bad idea is because the decision of what db to use is made before installation and I don't think it is a good idea for the code to have to figure out at runtime what db is being used.

Also there is no way that an OR mapper can do everything you need unless your app only uses basic CRUD. Take for instance the forums paging and sorting, I'm using temporary tables and custom SQL logic to make that work and I have never seen an OR Mapper that will take care of that kind of thing so you have to write some SQL. I know some of the mappers allow you to use stored procedures but then it gets back to what is this extra layer really doing for me other than adding overhead and complexity.

11/15/2004 8:18:21 PM
Gravatar
Total Posts 3

Re: OR Mapping vs DAL

Hi Joe

I mainly agree with you. I like to have control over the db too. At least DAO.NET gives you the possibility to store your sql-commands (i'm not sure with SP's) and the mapping in an external file like IBATIS does it.
(it's not that typical mapper  that does everything automagically for you)
If  DAO.NET doesn't find any sql-commands it generates them dynamically and that flexibility is great i think.
I'll keep on testing it...

Greets


1/4/2005 1:58:05 PM
Gravatar
Total Posts 2

Re: OR Mapping vs DAL

Hey Joe,

Since you seem to have some knowledge/experience with the choice between OR Mapping/DAL, perhaps you can clarify for me what the difference is between the two.  Or maybe you can point me to a resource that compares/contrasts the two approaches.

I've done a little bit of reading on OR Mapping but have to admit I don't really get what a DAL is in comparison.

I'm currently using DNN 2.1.2 for a few websites.  I know DNN uses the DAL approach but haven't had time to take a hard look at the code to help understand it.

I'm interested in mojoPortal because it "works with Mono" (TM) and I would like to move to Mono on linux (away from Win) as soon as I feel comfortable with the stability, compatibility, and availability of quality software options (like portal frameworks).

Thanks,

Michael
1/5/2005 5:58:24 AM
Gravatar
Total Posts 18439

Re: OR Mapping vs DAL

DAL stands for Data Access Layer and is often used to refer to the code that accesses the database whether or not this code is actually in its own layer.  In mojoPortal the data access code is truly in its own layer and totally abstracted so that the business layer has no knowledge of the underlying database platform. DotNetNuke for example has the business and data classes all mingled and compiled into the same dll as the web site. There may be conceptual layers but that is not what I call clean separation of business logic , data access logic , and presentation logic. The mojoPortal DAL is contained entirely in mojoPortal.Data.dll and there are currently 2 versions of this dll, one for MS SQL and one for MySQL. At some point I may also create a version for PostgreSQL, and could possibly even create a version that stores data in xml files.  Using the DAL approach, the code in the DAL is written specifically for a particular db platform.

The supposed benefits of OR mapping is that it saves a lot of time because you don't have to write a lot of repetitive DAL CRUD (Create, Retrieve, Delete Update) code but there is some degree of performance hit as a trade off for this convenience.  I don't claim to be an expert on OR mapping, there are a lot of them out there with a lot of differences between them in the db platforms they support and in the implementation details. Most of them use xml files to map db tables to business objects and can dynamcially generate basic CRUD SQL statements for you for the dbs they support.  Some of them allow you to specify stored procedures instead of using the dynamic SQL.  This is important since most apps use more than just standard CRUD. For example there is complex SQL logic to implement paging and sorting in the forums of mojoPortal that cannot be achieved with simple table selects.

My reasons for staying away from OR Mappers with mojoPortal are:

  1. I can achieve the same time saving with a code Generator to write the standard CRUD for the DAL. I use CodeSmith Studio with custom scripts I wrote myself so the CRUD generated is exactly the code I would write.  The non-standard DAL code I write by hand but the generator saves me significant time. I often use it as a starting point even if  I have to modify the code extensively after its generated.  In fact I use CodeSmith to generate most MS SQL Stored procedures and also to stub out my business classes.
  2. The code in my DALs is much more optimised for the specific db platform and gives better performance and is cleaner and easier to understand in my opinion.
  3. Learning to use an OR Mapper may be easier than learning multiple db platforms but many of them are very complex. There is a 400 page book for using NHibernate for example.  I think using an OR Mapper would add a lot of complexity to my solution without providing significant benefits that I don't already have. I would wager that many of them have more code in them than the whole mojoPortal framework currently has.
  4. SQL skills are very common. OR mapping adds a grey box between the application code and the db.  Chances are mojoPortal will be installed and used by companies that either have in house MS SQL or MySQL expertise. I want people who have these skills to be able to take the source code and extend it to meet their needs by seeing code they can understand readily.

I don't say that no-one should use them or that it is bad to use them but so far I'm not sold on the supposed benefits of that approach for my own work. Others may disagree with my points.

1/5/2005 12:26:01 PM
Gravatar
Total Posts 18439

Re: OR Mapping vs DAL

Here is an interesting post on Dino Esposito's blog about Object Spaces which is the MS OR mapping implementation coming out (I think) in .NET 2.0. He refers also to a another blog discussing performance in OR mapping or at least the MS implementation.
3/6/2005 2:21:26 AM
Gravatar
Total Posts 18439

Re: OR Mapping vs DAL

For those who would rather have a web site framework that uses OR mapping, you can checkout Cuyahoga Web Site Framework by Matijn Boland at http://www.martijnboland.com/cuyahoga/1/view.aspx
It runs on mono with MS SQL, MySQL, or Postgre SQL and uses NHibernate for the OR mapping. Looks like a good design though quite different from mojoportal. I still hold to my view on OR mapping but thought I would point out this project for those who disagree with me. I respect the choice to use OR mapping for those who prefer that approach. I don't say its a bad idea but it is not what I would do for reasons I've already stated. Still I respect that others may disagree and choose differently than I do.
3/26/2005 11:04:27 AM
Gravatar
Total Posts 4

Re: OR Mapping vs DAL

O/R Mapping vs DAL always causes lots of discussions., but I think in the end we all just want one main thing and that's improving productivity. The rest is all a matter of personal preferences. I really don't feel comfortable with generated code and that's one reason why I chose the O/R mapping route.
I'm glad to see you use Codesmith to generate most of the boring stuff so you can concentrate on the fun stuff.

But still some remarks :):

You mentioned that your DAL code is cleaner and easier to understand. That's fine but with an O/R mapper you don't have any DAL code at all so I think that is as clean as you can get.
Now about learning an O/R mapper: NHibernate is not easy, but writing good Codesmith templates (I don't consider manually writing a DAL a viable option) isn't easy either.
3/26/2005 11:42:15 AM
Gravatar
Total Posts 18439

Re: OR Mapping vs DAL

Hi Martijn,

Yes I agree its a matter of preference and style.   I can certainly see why many people like O/R mappers but its not my preference.

>I really don't feel comfortable with generated code and that's one reason why I chose the O/R mapping route.

I thought O/R mappers do generate SQL statements, do they not?

I found it pretty easy to write scripts for Codesmith because it is so similar to writing asp and I've done a lot of that.  I do carefully review every bit of generated code but for standard crud it generates very close to what I would write since I wrote the script.  I include my Codesmith scripts in the source code.

Joseph Hill just completed a new DAL for PostgreSQL that I plan to release soon (He just committed it today).  He also wrote Codesmith templates for PostgreSQL that should help me going forward with new development and supporting 3 data layers. 

In any case I respect and think highly of your opinion  and appreciate your input on this and especially on the Lucene.NET search engine.  Having your code to reference and your advice about dropping and re-creating the documents probably will save me a lot of heartache when I start working on the search feature.

Best Regards,

Joe

4/12/2005 5:12:47 PM
Gravatar
Total Posts 2

Re: OR Mapping vs DAL

I don't care to convince you one way or another.  My only interest in this topic is in learning, as I'm contemplating creating my own CMS from scratch.

There's a few things you've claimed that I don't understand.  First, you claim there's things you can't do with OR Mappers because they only support CRUD.  What else would you realistically want to do?  I know you mention the forums paging and sorting.  The paging I can almost see, because this is highly DB specific.  However, I wouldn't be surprised if some OR Mapper can handle this.  And even if not, you can implement the paging through cached data instead of always hitting the DB.  As for the sorting... most OR Mappers include a query language (like Hibernate's HQL) that's usually as powerful as SQL.  You mention using a temp table... but I generally find that to be a poor solution in all but the most extreme cases.  So, what am I missing here?

I'm not sure I agree with your point about code generation either.  The generated code is still long and not necessarily easy to understand.  It's certainly not easier to maintain.  Find a bug and you'll have to fix it in every piece of already generated code.  The OR Mapper on the other hand is an abstraction.  It simplifies the code which helps not only at the time of creation, but also during maintenance.

The point about being optimized *may* be true... but that's likely premature optimization.  Applications I've used that were implemented with OR Mappers perform just fine.

The point about complexity is both true and false at the same time ;).  Certainly OR Mappers are at least as complex as SQL, and so if you know SQL but don't know the OR Mapper there's a lot to learn.  However, there's also the complexity of the DAL and the ADO.Net to consider.  For most things I think the code for the OR Mappers is less complex than the code for ADO.Net.

Your target audience's skill set is absolutely a valid concern.  The only one I don't find any fault in, actually. ;)

I'm not trying to say you're wrong.  That would be the height of arrogance.  But since my experience with OR Mappers is not very extensive yet, I'm wondering how valid your remarks are in light of these "devils advocate" points of view.  NHibernate in particular seems to be a fairly simple yet powerful OR Mapper that would be well suited to this type of project.
You must sign in to post in the forums. This thread is closed to new posts.