How can I improve my business layer objects mapping into a database? Is it time for a O/R mapper?
Asked Answered
T

4

2

As I began writing web applications with ASP.NET I started with small projects that used a Linq-To-SQL mapper for database access to a MSSQL Server.
After gaining some experience, I switched into a classic three-tiered approach with a graphic Layer, business Layer, and a data Layer. The only function of the data layer was to provide insert/update/delete-methods without any logic and logic the form of selection methods.

Over the time I realized that it would be better not to provide the database classes up to the GUI (took some time, unfortunately). I switched to using business classes in the BL that are used for all operations performed by the BL and displayed by the GUI in the form of getting List from the business layer.
A great advantage is that I can provide additional properties that are not represented by the database itself. However, I did that mapping inside the business layer myself with methods that mapped the corresponding business layer class to the database class.

I guess that's where O/R mapper come in handy? Until now, I haven't realized their purpose, but I think I just found it. I've recently tried out using the new Entity Framework with .NET Framework 4, but I'm only using it like the Linq-To-SQL DataContext.

Is there a way to achieve the mapping automatically? If yes, is that something the new Entity Framework provides or do I need to look for a O/R Mapper like NHibernate?

Thermotherapy answered 2/9, 2010 at 19:47 Comment(0)
T
1

LinqToSql is an ORM, so you are already using one. Taking LinqToSql out and replacing it with EntityFramework or NHibernate won't solve the problems you appear to be having right now.

Here are some things you should learn more about to help give you additional context:

Touched answered 3/9, 2010 at 10:45 Comment(0)
R
4

I use NHibernate exclusively in my projects. I like the control and flexibility it gives me. There is a 'shortcut' called Active Record that uses NHibernate under the covers but provides a really nice an simple interface to NHibernate.

NHibernate has a steep learning curve, but when you get past that - it is really smooth sailing. When (and if) you venture the way of NHibernate, check out Ayende for cool tips.

Refund answered 2/9, 2010 at 19:58 Comment(1)
AR is fine, IF you are SURE you will NEVER want to do ORM any other way. Stripping AR implementations, especially decorators, back out of your domain is a real pain. I generally prefer the Repository pattern; the ORM on the other side can be anything you want, from a roll-your-own stored proc system to Linq2SQL to NHibernate to EF, and if you've structured your IRepository interface nicely your code will never know the difference.Cowling
J
3

(Entity Framework is an O/R Mapper.)

If you're serious about getting your hands dirty with ORM (but relatively new to that area), I highly recommend something like TekPub's videos on these topics. You'll be able to see these tools in use starting from scratch. It is a graceful introduction to some simple, but real-world issues like the ones you mention.

Jeu answered 2/9, 2010 at 19:57 Comment(0)
B
1

I've had a great time using Entity Framework 4.0 (+ the CTP). I think you'd have a much easier time dealing with an ORM like that. EF4 provides everything you need to interoperate with MSSQL from C#/.NET. You won't have to write a single line of SQL, and it has full support for LINQ (through ObjectQuery).

Burkhart answered 2/9, 2010 at 20:49 Comment(0)
T
1

LinqToSql is an ORM, so you are already using one. Taking LinqToSql out and replacing it with EntityFramework or NHibernate won't solve the problems you appear to be having right now.

Here are some things you should learn more about to help give you additional context:

Touched answered 3/9, 2010 at 10:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.