Resources for Building N-tier Applications

Published 09 April 08 09:05 AM

I've been getting a lot of mails lately from people trying to build n-tier applications with Visual Studio 2008. Luckily, VS now makes it much easier to build these kinds of applications which have pretty much become the "norm" these days. Here's a feed of items I'm building that should help you get started.

I've been really busy this week tagging items like this in an effort to revamp the Visual Basic Learn area of the Dev Center. The content there is still very popular but it's looking pretty dated at this point since the release of Visual Studio 2008. Look for changes to roll out there very soon. If you have some favorite pages to share please pass them along! Basically I'm trying to surface some of the best content from the Library, How-Do-I videos, Webcasts, books, learning plans, and blog posts on a variety of topics. Look for more topics like WPF, WCF, WF to be added to the Learn tab as well.

Enjoy!

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Airline Travel » Resources for Building N-tier Applications said on April 9, 2008 2:01 PM:

PingBack from http://www.travel-hilarity.com/airline_travel/?p=2558

# Schneider said on April 17, 2008 4:44 PM:

Looks like most of the samples are using DataSets. Do any of them use actual business objects? I can't stand these types of examples. There a lot of reasons to not use a DataSet.

# Beth Massi said on April 17, 2008 9:02 PM:

Hi Schneider,

There are at least 4 articles in the feed that explain how to do this. You can also take a look at this sample.

http://code.msdn.microsoft.com/linqntier

HTH,

-B

# Schneider said on April 18, 2008 11:36 AM:

Thanks,

I know how, I work on n-tier applications every day. I Just hate working on everyone else crappy DataSet based code which is hard to maintain. By providing bad examples here, it just furthers the problems.

Keep in mind some people are not using LINQ/WCF yet.

# Beth Massi said on April 18, 2008 12:46 PM:

Hi Schneider,

Datasets are very useful in many scenarios, just because they do not fit well with your architecture doesn't mean that they won't work in other architectures. I have guidelines in the beginning of this article. http://blogs.msdn.com/bethmassi/archive/2008/04/12/linq-to-sql-n-tier-smart-client.aspx

If you're looking for information on SOA there is a good amount available on MSDN.  You can start here: http://msdn2.microsoft.com/en-us/architecture/aa948857.aspx

HTH,

-B

# Avi said on April 20, 2008 6:59 PM:

I appreciate the work that went into these videos, but I found them extremely unhelpful. There are so many new concepts, and no explanation of why these new methods are being introduced. Why separate the data access layer into two classes? What exactly is an entity? Why use a service? What benefit do I gain by complicating things even further in this way? I watched both the Harry Miller "Creating an N-Tier Data Application" and your "How Do I: Use DataSets in an N-Tier Application" videos, and felt totally lost throughout them both. You both just click around and say "do this and this", without any real explanation of why to do it all.

Maybe in addition to the "How-Do-I" series, there should be a "Why-Do-I?" series.

Feeling really frustrated!

# YAG said on April 20, 2008 9:09 PM:

Hey Avi,

Check out http://msdn2.microsoft.com/en-us/library/ms973829.aspx for a good explanation of the tiers and why you use separate projects for each tier. It also goes into the benefits and disadvantages of n-tier and how to select how to architect your app.

# Avi said on April 21, 2008 12:34 AM:

I understand the benefits of the 3-tier system (presentation, business logic, data access), but these videos had even further compartmentalization (for example, splitting the DAL into two classes). I'll check out the article you recommended, but its six years old, so I don't expect it to cover the newer issues that well.

# Beth Massi said on April 21, 2008 12:38 PM:

Hi Avi,

Thanks for the feedback. In the n-tier video I explain some of the common reasons for going n-tier like scalability and security reasons. The reason why you should take a layered approach to your architecture, regardless if you physically separate the tiers, is mainly for maintenance. Separation of concerns is key to any large system so that maintenance and testing costs stay down.

The article is still a good one to read on the "why-to", and you can use the videos as the "how-to". In the video I'm not separating the DAL into two projects. I'm separating the dataset generated code. There's a difference. Many systems use the DataSet as the data transfer object (the object that is serialized to the client) and in order to do that in a n-tier system you need to separate the structure of the dataset from the data-access logic stored in the TableAdapters.

The video shows how you can separate the concerns by moving the TableAdapter code (the data access layer) away from the structure of the data (the DataSets a.k.a entities) and how to share the types on the client and server so validation rules can be reused. This architecture should not be confused with SOA, but it is still a common architecture for systems written in all .NET (clients and servers).

HTH,

-B

p.s. YAG thanks for the link.

# Yuri said on April 21, 2008 3:56 PM:

I've built an n-tier applications based on your demo videos and they worked well.

The second time I built it, the validaton logic is not working, the event in DAL is not firing, what could be a reason for that?

# Yuri said on April 21, 2008 5:45 PM:

I guess now I know what I did wrong.

I used the DataSet exposed by the DataService instead of that exposed by the reference to the Business Logic Layer.

Why actually can't I work just with the service?

Like this the application interacts with the middle-tier BLL not just via a Data Service but also directly through the reference. What's the point then in using the Data Service?

# Beth Massi said on April 21, 2008 6:55 PM:

Hi Yuri,

In the video it demonstrates one way to build an n-tier app that has both a .NET client and server by type sharing the entities. The entities is ONLY the structure of the data and validation, not anything to do with the communication to the database. The service is the middle-tier that is hosted on a web server in this example. This stateless service allows you to scale out (farm) the middle-tier easily. If you allowed the client to connect to the data access layer directly then you would have a connected client-server application and you would need to invest in scaling your database server (which is costly) instead of just farming your service layer. This is a very common reason for building the application as n-tier. Additionally, even if you don't physically separate the tiers with a service, it's a good idea to logically separate them for maintenance reasons.

HTH,

-B

# Yuri said on April 22, 2008 1:27 AM:

Hi Beth,

thanks for the prompt reply! Now it's clear to me.

All in all, I am very happy with the new features offered by VS2008 as they help tremendously to develop business apps quickly.  I also found your article DS vs LINQ very interesting.

My other question would be, could you make a tutorial on how to deploy such a n-tier application?

As I understood from MSDN, there are several ways to deploy a service, even one without having to run IIS. That is great, because my employer wouldn't like an idea of running an IIS Server among Linux servers, simply because he has no admins for that.

By the way, we are using DB2 as the back-end and the n-tier architecture proposed here works with DB2 the same like with SQL Server which was a nice surprise to me.

I cannot try LINQ yet, because LINQ to Entities doesn't work with DB2 yet.

Best regards,

Yuri

# Yuri said on April 22, 2008 2:17 PM:

BTW I have another question.

All "how to do" videos are based on WinForms, why actually you are promoting only the Winforms?

# Yuri said on April 22, 2008 2:17 PM:

BTW I have another question.

All "how to do" videos are based on WinForms, why actually you are promoting only the Winforms?

# Beth Massi said on April 22, 2008 2:24 PM:

Hi Yuir,

I plan on doing some on WPF as well. Winforms is more mature in its tooling when it comes to working with data so it's easy to learn it. If you're interested, check out www.windowsclient.net for WPF videos.

HTH,

-B

# Yuri said on April 22, 2008 3:48 PM:

I have found a sample project using DataGrid in a Silverlight app. Cool!

http://silverlight.net/GetStarted/

# Brian in England said on May 2, 2008 5:19 AM:

Hi, Beth

I can understand allot of the comments on here. Especially the ones from Avi.

Many of the videos in the ‘how to forms over data series’ don’t apply to an  N-Tier Application. Please Thanks can you put all this new programming in to new video, as an add on the ‘Use DataSets in an N-Tier Application’ as I find it hard to follow.

p.s maybe you could write a small book on this new technology as there are none that address these issues!

Thanks

Brian  

# Mitch said on September 9, 2008 8:11 AM:

Hi, I watched the video How Do I: Use DataSets in an N-Tier Application? and tried to rewrite the code in VS 2008 using C# - everything was working till I got to the saving and updating of the new rows - they saved but the grid didn't update, although I used the same code, but in C#.I found a  dirty solution but could you tell me why it didn't update the ids?

private void ordersBindingNavigatorSaveItem_Click(object sender, EventArgs e)

       {

           this.Validate();

           this.ordersBindingSource.EndEdit();

           var proxy = new NorthwindService.Service1Client();

           var changes = (NorthwindEntities.OrdersDataSet)this.ordersDataSet.GetChanges();

           if (changes != null)

           {

               if(proxy.SaveOrders(changes))

               {

                   var addedrows = from row in this.ordersDataSet.Orders

                                   where row.RowState == DataRowState.Added

                                       select row;

                   foreach (var row in addedrows.ToArray())

                   {

                       row.Delete();

                   }

                   //If we substiture the following two lines with

                   //this.ordersDataSet.Merge(proxy.GetOrders("ALFKI"));

                   //it updates (but makes a new request for the whole DataSet)

                   this.ordersDataSet.Merge(changes);

                   this.ordersDataSet.AcceptChanges();

                   MessageBox.Show("saved");

               }else{

                   MessageBox.Show("not saved");

               }

           }

       }

# George C Ryall said on January 1, 2009 8:33 AM:

Beth

I have followed your video series and am a real bif fan.  I like how easy they are to understand for us neophytes.  I have been following them in series usinf 2008 Express and my own personal MS/Access dataset.  EVrything has worked just as described until I got to the N-Tier video.  I followed each of the steps as described, but when I got to the part about double clicking the dataset xsd (Again it's a dataset based on an MS/Access table), I do not see the property "DataSetProject" to direct it to the Entities project.

My question is can N-Tier applications be developed in the the Express version or do I need a more powerful version of Visual Basic?  If it is possible with Express, Then is the fact that I am using an MS/Access database the problem?

I would appreciate any halp you can provide me.

Keep up the fantastic video series.

# Beth Massi said on January 5, 2009 5:27 PM:

Hi George,

Unfortunately N-Tier Datasets are not supported in Express Edition. I've passed this feedback onto the team that made this decision in order to reconsider. You can also submit your feedback on http://connect.microsoft.com/

Cheers,

-Beth

# asset michael said on February 19, 2009 8:43 PM:

hi!

i want to use winforms to crud data from an SQL server in a shared web hosting. is this possible in an n-tier application just like your samples and videos?

thanks.

# asset michael said on February 19, 2009 8:52 PM:

and how will i deploy it? i.e. where will i put my projects/files?

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

About Beth Massi

Beth is a Program Manager on the Visual Studio Community Team at Microsoft and is responsible for producing and managing content for business application developers, driving community features and team participation onto MSDN Developer Centers (http://msdn.com), and helping make Visual Studio one of the best developer tools in the world. She also produces regular content on her blog (http://blogs.msdn.com/bethmassi), Channel 9, and a variety of other developer sites and magazines. As a community champion and a long-time member of the Microsoft developer community she also helps with the San Francisco East Bay .NET user group and is a frequent speaker at various software development events. Before Microsoft, she was a Senior Architect at a health care software product company and a Microsoft Solutions Architect MVP. Over the last decade she has worked on distributed applications and frameworks, web and Windows-based applications using Microsoft development tools in a variety of businesses. She loves teaching, hiking, mountain biking, and driving really fast.

This Blog

Syndication

Page view tracker