Jump to content

Pulling Data from the Data layer

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Pulling Data from the Data layer Rate Topic: -----

#1 User is offline   mouse_catcher 

  • W.R. Private
  • Group: Members
  • Posts: 42
  • Joined: 26-July 07
  • Gender:Male
  • Location:Auckland - New Zealand

Posted 08 August 2007 - 02:59 PM

Hi

Now I didn't want to get my other post on 3rd Party grids off topic but I encountered a dilemma when playing around with my grids.

I'm developing a web app at home (trying to get out from under tha man) and I thought I'd go through the cruel and unusual pain of creating a n-tier framework from scratch. How hard can it be right. right......ok you can all quit laughing now.

My question is. What method do people use to retrieve data to display in grid controls. For example at work we pull it out from the data layer in xml and on the presentation layer we use xslt to transform it into an html table.

Now I start looking at these grids and they obviously like to play with the .net datasources. Seems the ObjectDataSource fits nicely onto a n-tier architecture but I find DataSets to be a bit well, restrictive when massaging data on the datalayer if that makes sense.

So what do you use people? Datasets? Xml? Collections of business entities?
0

#2 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 08 August 2007 - 03:41 PM

In the last year I've moved to using n-tier architecture for most of my work. I tend to generally model things after the example used in the really great book ASP.NET 2.0 Website Programming - Problem, Design, Solution . There's quite a bit of coding upfront to put the tiers together so one of the first things I did was to build a little web app that looks at the SQL server table of my choice and build both all of the classes for the different tiers and also all of the SQL stored procedures used by them. Then I can go in and start customizing the business logic, etc as needed.

Anyway, to your question. Short answer: Collections of data entities. I pass data around my app using objects (for example dFruit). The object is basically just a recreation of the database table and doesn't have anything more than the required fields. My DAL grabs a recordset from the db, then loops through the rows creating an instance of the data class for each row and then adding it to a generic list List<dFruit>.

The business logic layer (BLL) grabs the List<dFruit> from the DAL and builds a List<Fruit> of the actual business entities and handles any other things that need to be done at that level all in a small GetFruitFromdFruit() function (inside the business object). So that's where the collection of business entities gets created from the collection of data entities.

So now on the presentation layer you can use an ObjectDataSource to bind to the List<Fruit> and display as needed. A great thing about using business entities is that you can have one-to-many data relationships represented by using more generic Lists as properties of your main object.

Occasionally I put one more small layer between the BLL and the ObjectDataSource which is just an interface to cut down the number of fields passed through, or some other presentation related massaging that I want to do of the generic List that's getting passed.

I also use the Provider pattern in my DAL just in case I want to swap out database engines at some point.

It does seem like a lot of work to code this up, but it makes development much cleaner and I'm really in love with building apps this way now (in fact I've slowly been working on a series of articles about how to do this here on the forums).

Finally, in the upcoming VS 2008 you'll be able to replace doing all this by hand by using the LINQ technology.

If you want to see some example or anything let me know.
0

#3 User is offline   mouse_catcher 

  • W.R. Private
  • Group: Members
  • Posts: 42
  • Joined: 26-July 07
  • Gender:Male
  • Location:Auckland - New Zealand

Posted 10 August 2007 - 06:27 AM

Thanks Catalyst. I was so excited when I read your post at work (It just clicked) that I couldn't wait to get home and start coding - gee I'm such a geek :D

I was wondering whether I'd ever get around to using generics. I understood the theory but with no practical application in my work - meh. Thats another reason I'm creating a framework from scratch, it gives me a chance to test theories and learn new technologies I'm unable to implement while slaving for the man.

The concept you outlined turns out to be the missing piece I need (among others I'm sure). Datasets and Xml (which is what I knew) was kinda leaving a bad taste in my mouth. As it turns out I already have my business entities so it was relatively simple to plug in the lists as you described.

Works a treat with the ObjectDataSource as well, although I haven't implemented custom paging and sorting yet.

:notworthy:
0

#4 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 10 August 2007 - 06:01 PM

Great! The custom paging/sorting isn't as difficult to do as you might think. I also didn't particularly like the DataSet method, it seemed to add a bit of a black box and I like knowing what's going on behind the scenes.

Generics are awesome, I use them all the time now.

Sadly there's not nearly enough examples out there for using the ObjectDataSource compared to the SQL one. As I mentioned before the architecture I use is based on the one in a book. You can actually download the full project from the book, it's on the asp.net website as a starter kit: http://asp.net/downl...the-beer-house/

If you grab that you can see how he passes data between the layers, how the data provider is built, custom config sections, all sorts of useful stuff. I don't do things exactly like he does , but I think it's a great base to work from.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users