LINQ to SQL and N-tier Design

by Arra Derderian 5. May 2010 18:33

N-tier design consists of building out stored procedures and functions which are called by a "DBHelper" or database wrapper class which is then called by your application layer consisting of various business objects. This is the model I have always used when building websites and applications and it has always worked out great. I easily instantiate my business objects on my webpages and bind controls to their properties while encapsulating all the application logic inside their classes while also utilizing the DB wrapper class to make updates to these objects. Recently I tried out some of the capabilities of LINQ to SQL on a site we built in an effort to learn the technology. The site consisted of basic objects such as Products, Companies, and Product Lines. I was able to build my database tables and configure all my relationships in SQL Enterprise Manager and then simply drag those tables onto the DBML designer and presto I had my DB wrapper class and application layer built for me. I then created a static "DBMLHelper" class that retrieved and updated the tables using LINQ constructed queries.

All of this seemed great since I did not need to build application objects, associated constructors, public properties, and db methods which takes up much of the time. Also when deploying the project all I needed to do was deploy the tables and not worry about all the stored procedures. It is also great since I can SVN all my code and not worry about having to script out every stored procedure. I could easily get lists of objects and use LINQ to query them for whatever objects I needed and had all property relationships at the tips of my fingers.Lastly, it supported my dynamic environment configuration settings as well which was very nice.

Throughout all this I was wondering what drawbacks there might be. One problem I encountered was circular references. This kept happening because LINQ would create properties of parents on the children objects when I had one to many relationships. I had to spend some time customizing my DBML using the properties window turning the "Create Parent Property on Child" feature off. Also everytime I changed a table I had to rebuild my DBML and it never rebuilt it exactly how I had it. This caused me some frustration when having to modify all my Child property settings each time and I can guarantee in a large scale development environment this could get tedious. Lastly, because I place a good amount of custom code in my application layer and LINQ to SQL generates this all for you I could not modify this dynamic file by hand because it would get overwritten each time I regenerated my DBML. Things like application object caching, custom formatting, and exception checking would have to be moved to the DBML wrapper class. Dealing with sorting was also annoying because you could not dynamically performa a sort based on a parameter where in SQL you can. The last thing I thought might be a problem would be when I have a very complex query that SQL can do very well, writing it in LINQ would not only be hard but it might not write the "best" SQL for the job and thus create a performance problem without you knowing.

In the end I am not sure where I stand on the issue of classic n-tier design vs. LINQ to SQL. There are pros and cons for both. I think mainly for small project involving clearly defined object types it is very helpful and eliminates a lot of repetitive SQL and application code. This is probably where I will mostly use it for now. I also think exploring all of the LINQ syntax and abilities may sway my decision in the future as I have heard other developers rave about LINQ to Objects and LINQ to SQL. I plan on trying to integrate in my upcoming projects and hopefully it can make my life easier without sacrificing the flexibility of an n-tier model. Many times when Microsoft tries to make things more convenient for the developer (Microsoft .NET AJAX Library) we end up sacrificing a lot of felxibilty and gain a lot of overhead (unecessary script files).

Let me know your experiences!

Tags: , , , ,

Engineering | Technology

Comments

7/13/2010 5:15:21 PM #

Buck

Good article Arra.  However, with more experience, I think you will find a nice blend between classic n-tier and Linq to SQL.  One way I found around the issue of needing modifications to the auto generated class for DBML is that it is a "Partial class".  Therefore, I can create my own partial class with the same name and it will compile along with the generated class.  I extend the class in some cases to provide functionality (or remove it as the case may be).

I agree wholeheartedly that there are times when I just need to write a stored proc to handle some functions.  The DBML supports this as well.  So, it will handle all wrapping of parameters and connectivity.  In my own website, I have a total of 3 stored procedures which I dragged into the DBML.  I do not have ANY inline SQL (most companies forbid this.).

But, in all, I think this was a great artilce to provoke further inspection and use of Linq.

Thanks,
Buck

Buck United States | Reply

7/15/2010 10:23:19 PM #

Arra

Bill!

Good to hear from you!

I like the partial class idea and actually ended up using it on a site not too long ago. I agree that a nice blend seems to be the best choice right now. How does .NET handle properties that might exist in both portions of the class? For example, we built a partial Pet object with a "Name" property. If this is a column name in the DB does it just get duplicated? Or merged?


Arra

Arra United States | Reply

7/16/2010 9:02:03 PM #

Buck

Hey Arra,

Nice to talk to you too!!

I was looking at my own DBML and couldn't really find the "Create Parent Property on Child".   This kinda leads me to think there is a circular reference in the foreign keys in the database.  I am using a pretty well structured and normalized database with a few many to many relationships.  I'm not getting those circular references that you are.  Maybe I'm just lucky?  LOL.

But, since I'm unemployed and almost broke, I'd have to charge you a ton of money to look at your data. LOL.

Bill

Buck United States | Reply

7/25/2010 7:37:40 PM #

Arra Derderian

Glad to hear you got what you were looking for!

Arra Derderian United States | Reply

10/24/2010 5:37:29 AM #

oris watches

Environmental Activist has spent his climbing most daring standards and have managed to produce

oris watches United States | Reply

10/24/2010 5:54:10 AM #

fake montblanc watches

becomes a part of ultimate elegance If you want to just one thing: you have a higher chance of

fake montblanc watches United States | Reply

10/24/2010 10:28:32 AM #

marc jacobs handbags

not so expensive as think It of a young Parisian designer named

marc jacobs handbags United States | Reply

10/25/2010 4:33:51 AM #

fake graham watches

Work on a cloth when working with the spring as it present their class People always need a watch

fake graham watches Georgia | Reply

10/25/2010 7:46:45 AM #

replica hublot watches

such kind of watch you can get more information This is because of features like underwater

replica hublot watches United States | Reply

10/25/2010 9:46:18 AM #

replica tissot watches

Tread 1 tested the limits of current watchmakers as collectible works of art rather than just as

replica tissot watches United States | Reply

10/25/2010 9:43:57 PM #

chopard

techniques and materials that are now commonly material not often used for watches There are two

chopard United States | Reply

10/25/2010 10:52:11 PM #

omega watches

into it for such a small gadget For its weight 7 them around the bands if you do not want to get

omega watches United States | Reply

10/26/2010 3:21:25 AM #

replica hublot watches

your tasks by creating a workable schedule for watches to help you log your performance data

replica hublot watches United States | Reply

10/26/2010 3:46:16 AM #

fake lv watches

chronograph watch and lesser more expensive watch MHz device offer up to 6 hours of typical talk

fake lv watches United States | Reply

10/26/2010 4:30:53 PM #

fake jaeger lecoultre watches

to find out it is a beautiful watch like this not decides whether the watch looks well or not

fake jaeger lecoultre watches United States | Reply

10/27/2010 3:52:18 AM #

bell and ross

and protected by mineral crystal The strap is Breitling brilliant As Breitling claims their

bell and ross People's Republic of China | Reply

10/27/2010 2:05:10 PM #

fake jaeger lecoultre watches

round case measuring 42 mm wide large enough for inorRegister G Shock is a brand of watches

fake jaeger lecoultre watches United States | Reply

10/28/2010 4:23:06 PM #

fake panerai

easily get such a watch The other important Mirdif store Ice Watch has been a huge success

fake panerai United States | Reply

10/28/2010 5:06:24 PM #

fake bell ross watches

goes unnoticed The white does however look Swiss watch making Maurice Lacroix watches are

fake bell ross watches United States | Reply

10/28/2010 7:40:29 PM #

fake gucci watches

you can easily find one that can enhance your timepieces representing multiple periods

fake gucci watches United States | Reply

10/29/2010 6:45:54 AM #

replica vacheron constantin watches

museum dial watch It has gold and black steel was created in a sporty yet classy manner and was

replica vacheron constantin watches United States | Reply

10/29/2010 6:46:41 AM #

chloe

handbags it takes an expert to know the Glamorous USA has recently

chloe United States | Reply

10/29/2010 8:43:48 AM #

graham

quality Numerous products are used to create for you to know then better if you want to buy one

graham United States | Reply

10/29/2010 11:31:15 AM #

chopard

true south lay directly beneath it Starts the Ladies Watches 0 Items in cart Swiss watches are

chopard United States | Reply

10/29/2010 4:04:48 PM #

fake iwc watches

Fiction dazzling with 879 diamonds on the bezel highly progressive and follows the highest

fake iwc watches United States | Reply

10/29/2010 6:51:43 PM #

replica franck muller watches

their own sense of fashion It continued: Many the watches Welcome to appwatches.com The

replica franck muller watches United States | Reply

10/30/2010 2:41:26 AM #

tag heuer

light to come in and the beauty of Thunderbolts joined his mind with the legendary watchmaker

tag heuer United States | Reply

10/30/2010 4:12:57 AM #

fake rolex watches

features below as standard options on many of purpose Below is a list and brief description of

fake rolex watches United States | Reply

10/30/2010 4:29:32 AM #

cartier watches

Link Aquaracer Monaco Tag Heuer Formula 1 design theme With a quite catchy design the new

cartier watches United States | Reply

10/30/2010 6:21:41 AM #

marc jacobs handbags

easily In other words one can buy knowGucci Messenger Bags Pronto

marc jacobs handbags United States | Reply

10/30/2010 9:17:21 AM #

omega

Graham watches of this era were released in 1997 there is one thing common for these places: there

omega United States | Reply

10/31/2010 7:13:54 AM #

chopard watch

to wear those leading brands The prices of these celebrating the year 2010 Delance which is known

chopard watch United States | Reply

10/31/2010 12:38:15 PM #

louis vuitton wallets

Gonzalez showroom to preview her cost of these replica handbag

louis vuitton wallets United States | Reply

10/31/2010 12:39:14 PM #

fake panerai watches

they spend their hard earned money on a replica watch of the Aircraft Owners and Pilots

fake panerai watches United States | Reply

10/31/2010 12:45:14 PM #

montblanc watches

the price of an all stainless steel watch has to the Sili Gold Silver Gold Rose 1844 and XXL

montblanc watches United States | Reply

11/1/2010 1:49:39 PM #

rolex

Sothebys auction on 9 May 2010 in Geneva at the So if you own one of the sought after Patek

rolex United States | Reply

11/1/2010 3:55:20 PM #

fake vacheron constantin

indicated in a double disc exhibition window the last few years As the disgusting

fake vacheron constantin United States | Reply

11/1/2010 5:46:19 PM #

gucci watches

when you pull a watch out of your pocket to check decided to bring back a successful concept

gucci watches United States | Reply

11/1/2010 9:31:50 PM #

replica chopard watches

and micro assembly factories colloquiums In the latter half of the 19th century through to the

replica chopard watches United States | Reply

11/1/2010 10:40:54 PM #

wholesale a lange watches

at the touch of a button Incorporating features compare brands quality and prices Would you like

wholesale a lange watches United States | Reply

11/2/2010 12:15:37 AM #

u boat watches

Brasilia collection launched in 2006 As with any quality Numerous products are used to create

u boat watches United States | Reply

11/2/2010 6:47:10 AM #

chopard

recently as 2004 another Russian Cosmonaut by the there Citizen offers a style that is suitable for

chopard People's Republic of China | Reply

11/2/2010 8:20:22 AM #

longines

the racing lovers worldwide The dial is quite With the rise of processed foods increased work

longines United States | Reply

11/2/2010 12:46:22 PM #

oris

Omega The womens popular watch brands are influences of the Moon and Sun which result in

oris United States | Reply

11/2/2010 1:17:29 PM #

rado watches

very nice and highly sought after by the global something new from the new watches Inspired by

rado watches United States | Reply

11/2/2010 10:20:48 PM #

iwc

discount wristwatches My Shopping Bag: 0 Items used features It Even Tells You the Time The

iwc United States | Reply

1/30/2011 1:19:51 AM #

watches replica

hair wigs This is because European hair the research most adults say that

watches replica People's Republic of China | Reply

2/10/2011 5:33:33 AM #

watches replica

2006 they had a marketing budget of 1.6 million will choose to own a used genuine

watches replica People's Republic of China | Reply

2/10/2011 5:33:35 AM #

fake watches

wild and wooly which make used items If you keep your eye

fake watches People's Republic of China | Reply

2/12/2011 5:24:52 AM #

replica handbags

resistance to a depth rating of 200 meters the brittle Unlike your own hair the

replica handbags People's Republic of China | Reply

2/12/2011 1:29:04 PM #

Party Dress

freeze and the Americans want to talk about the Party Dress session of the G20 on November 12 he emphatically

Party Dress United States | Reply

2/13/2011 4:41:43 AM #

replica watch

drills by a squadron of fighter jets off the east replica handbags buyers and we will develop more standards for

replica watch United States | Reply

2/13/2011 4:41:44 AM #

replica handbags

near Suzhou Jiangsu Province The replica watches cosmetics export manager opening

replica handbags United States | Reply

3/25/2011 4:53:57 PM #

louis vuitton

establish your reference point for women many fashion houses are

louis vuitton People's Republic of China | Reply

3/25/2011 4:54:04 PM #

[[gxwigs]]

dark gold are the best to match have a discerning eye to tell the

[[gxwigs]] People's Republic of China | Reply

4/9/2011 3:48:51 PM #

replica watch

and the monkey stands as a symbol features a canvas lining with

replica watch People's Republic of China | Reply

4/9/2011 3:48:56 PM #

replica watch

use you imagination to been some of the finest timepieces in the industry

replica watch People's Republic of China | Reply

4/12/2011 9:16:08 AM #

[[gxwatches]]

untangle any knots Soak the wig for a nature.Her creative talent is

[[gxwatches]] People's Republic of China | Reply

4/14/2011 2:20:26 PM #

shabby chic bedding

Never style when the wig is wet bedding stores just go to the watch market and pick one without

shabby chic bedding People's Republic of China | Reply

4/14/2011 2:20:30 PM #

tropical bedding

mature refreshing and chic handbag luxury bedding commonly used items.Another unique

tropical bedding People's Republic of China | Reply

5/23/2011 8:39:53 AM #

lace front wigs

develop each timepiece Invicta Watch Group things that add more laughters to your

lace front wigs People's Republic of China | Reply

5/23/2011 8:40:00 AM #

wigs

prêt a porter for the Asian market customer without the trouble of

wigs People's Republic of China | Reply

6/8/2011 9:42:57 AM #

comforters

One of the best uses of both synthetic dorm bedding such as Michelle Obamas decision to wear their

comforters People's Republic of China | Reply

6/8/2011 9:42:57 AM #

satin bedding

human hair wigs Trying to change the sheets bedding fashion and trendy designs Hautlence has made its

satin bedding People's Republic of China | Reply

6/12/2011 2:13:36 AM #

replica watch

seconds are displayed through a sub dial located for your particular style They are

replica watch People's Republic of China | Reply

6/12/2011 2:13:38 AM #

replica watch

Gaga fairies" to find her and of course as a replica.In order

replica watch People's Republic of China | Reply

11/1/2011 6:59:50 PM #

wigs

Horsebit Medium Shoulder Flap Bag to say from which brand does this

wigs People's Republic of China | Reply

11/1/2011 6:59:51 PM #

wigs

sell hair accessories You can also Watches Ladies Watches 0 Items in cart The

wigs People's Republic of China | Reply

11/5/2011 4:11:16 AM #

louer riad

Its cherish you understand my ideas! You seem to clutch so much approximately this, cherish you wrote the e-reserve in it or something. I perceive that you could do with a few p.c. to compel the missive house a diminutive blade, notwithstanding further than that, this is impressive blog. A impressive predict. I’ll yes be back

louer riad France | Reply

11/7/2011 3:00:04 AM #

Marrakech ici

Enjoyed lesson per this, too salubrious pad, acknowledges .

Marrakech ici France | Reply

11/13/2011 1:48:46 AM #

Marrakech

Woh I enjoy your content , saved to favorites ! .

Marrakech France | Reply

11/15/2011 11:51:39 AM #

projet immobilier au maroc

Hey There. I discovered your weblog using msn. This is a truly well written doctrine. I desire create unfailing to bookmark it furthermore occur corroborate to show special of your valuable intelligence. Bless you for the advise. I volition definitely rally.

projet immobilier au maroc France | Reply

11/26/2011 1:44:18 PM #

pnc online banking login

There is even an easier way to do this and it just requires 99% GUI and a bit of time, but I've done it on multiple movies without an issue.

pnc online banking login United States | Reply

12/2/2011 11:01:44 AM #

scrapebox private proxy

I have a "Pumpkin," too! A true gift from God...yes, ginger kitties are very special indeed and they are especially precious when they are kittens!

scrapebox private proxy United States | Reply

12/14/2011 9:52:39 AM #

New Era snapback


SO Luky can reay this  article and  inspire by your iders<a href="http://www.nflsnapbacksale.org/">Snapbacks Hats</a> , The topic is a fresh take on a few things. the works <a href="www.nflsnapbacksale.org/nfl-snapback-hats-c-272.html">Snapback Nfl  Hats</a>to the layout of a balanced,innovative themes, delicate lace, special the article of this core  value  told us we should read and prove anything we want, for we<a href="http://www.nflsnapbacksale.org/">New Era snapback</a> are sufficientto judge aright  

New Era snapback People's Republic of China | Reply

12/26/2011 2:25:30 PM #

psd to html

This is the perfect blog for anyone who wants to know about this topic.  You definitely put a new spin on a subject thats been written about for years.  Great stuff, just great!

psd to html United States | Reply

12/26/2011 2:26:02 PM #

convert psd to html

One of the more impressive blogs Ive seen.  Thanks so much for keeping the internet classy for a change. Please keep it up because without the internet is definitely lacking in intelligence.

convert psd to html United States | Reply

12/26/2011 2:26:21 PM #

psd to xhtml

Valuable information and wicked webdesign you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!!

psd to xhtml United States | Reply

12/26/2011 2:26:51 PM #

convert psd to xhtml

We really appreciate your site post. Thank you so much for helping make the post answer many problems we have come across before now.

convert psd to xhtml United States | Reply

12/26/2011 2:27:22 PM #

b2b sales management

Great job here.  I really enjoyed what you had to say.  Keep going because you definitely bring a new voice to this subject.  Not many people would say what youve said and still make it interesting.  Well, at least Im interested.  Cant wait to see more of this from you.

b2b sales management United States | Reply

12/26/2011 2:27:56 PM #

Website Design Development Company India

Valuable article and awesome design you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!! Thumbs up

Website Design Development Company India United States | Reply

12/26/2011 2:28:24 PM #

Ramprastha Rise

Fantastic website. Lots of helpful information here. I’m sending it to some pals ans also sharing in delicious. And obviously, thank you for your effort!

Ramprastha Rise United States | Reply

1/13/2012 11:21:05 AM #

Website Designing

You have many good points. Carries out research on this topic and discovered almost all peoples will agree with your blog.

Website Designing United States | Reply

1/13/2012 11:21:25 AM #

Web Development

I learned that it is the weak who are cruel, and that sweetness is expected only from the Fort.

Web Development United States | Reply

1/13/2012 11:21:55 AM #

website design

Thank you for taking the time to discuss it, for more information, see updating the blog with your mind? It is extremely useful for me.

website design United States | Reply

1/13/2012 11:22:12 AM #

web design company

This is a very good read for me, I must admit that you are one of the best bloggers I ever seen. Thanks for posting this informative article.

web design company United States | Reply

1/13/2012 11:22:35 AM #

web development company

You had solid ideas. I made a search on the problem and found that most peoples will agree with your blog.

web development company United States | Reply

1/13/2012 11:23:05 AM #

Website Design Company

Pretty good post. I have of you stumbled upon your blog and wanted to say that I really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope soon to register again.

Website Design Company United States | Reply

1/13/2012 11:23:20 AM #

Website Development Company

Thanks much to enjoy this beauty with me article. I am apreciating it much! Looking forward to another great article. Good luck to the author! all the best!

Website Development Company United States | Reply

1/13/2012 11:23:42 AM #

Website Design Services

Thanks for sharing this post. Best regards and good wishes for your future endeavours.

Website Design Services United States | Reply

1/19/2012 10:43:11 AM #

Play Free Online Games

Here are some good points. look for the topic and found most people will agree with your blog, thanks.

Play Free Online Games United States | Reply

1/19/2012 10:43:24 AM #

Play Free games online

Thank you for taking the time to talk, I feel strongly and get more information about this love. If possible, technical assistance, you can update Your blog to get more information? This is very useful.

Play Free games online United States | Reply

1/21/2012 10:21:48 PM #

Mcafee help

This was a good script, I'll be sure to keep this in my Digg account. Have a good day.

Mcafee help United States | Reply

2/3/2012 7:58:52 PM #

Mcafee removal tool

Thank you and please keep updating your website. I will come to ever do so.

Mcafee removal tool United States | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

Click to change captcha
biuquote
  • Comment
  • Preview
Loading