Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server Database 2

Status
Not open for further replies.

techie4ever

Technical User
Jan 11, 2009
3
US
I am here because I am so confused by the terminology that is going on in ASP.NET. I am suppose to display some rows from an SQL database when a page reloads. As far as I have seen this can be done either in the ASP.net code (ADO.net) or in the C# code. What is the right way? When is what done?
 
the problem is your are confusing, languages and frameworks.
.net is a framework to compile code. c# is one language the .net framework understands, other are vb, ruby, python, j#, etc.
c# is a programming language. just like c++, vb, java, php, ruby, etc.
asp.net is a framework for fulfilling web requests.
ado.net is a framework for accessing persistent storage (ie: databases)

something you haven't mentioned is webforms. but most .net developers thing webforms and asp.net are the same thing they are not. I described asp.net above. webforms is an (overcomplicated) html rendering engine that runs on top of asp.net.

think of ado.net and asp.net as subsets of the .net framework. on works without the other. think of webforms as a template engine to generate html, nothing more. c# is how to write the code which may, or may not use anyone of the frameworks described above.

now to complicate this. webforms has objects which lets you directly access the database from the aspx file. DO NOT DO THIS. it breaks the principle of signal responsibility and creates untestable (as in automated testing) code.

not to mention that database access is a solved problem. with ORMs like LLBL, Nhibernate, ActiveRecord and WilsonORMapper there is no need to write ado.net code directly.

while this doesn't answer how to write the code, it should give you some ideas about what the different frameworks do.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Would you mind further describing the "principle of signal responsibility", please?
 
SRP: each object should have exactly one responsibility.
there are a series of principles known as the SOLID design principles.

Single Responsibility
Open Closed
Liskov Substitution
Interface Segregation
Dependency Inversion

chad myers has a great summary post on it.
Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks Jason. Single responsibility appears to be what I'm familiar with as "cohesion." I'll look at the link.
 
Thanks Jason. At first look at the (excellent!) link you've provided, SOLID appears to be related to concepts of cohesion, coupling and polymorphism. I'll digest this with interest.
 
@jason, thanks for the link. pablo's logo, it's a donkey right? =)
 
the donkey is the lostechies logo. lostechies is an aggregate feed of individual blog.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
thanks for all the explanation jmeckley. Can you please let me know what is the difference between using Datasets and Nhibernate or ActiveRecord or other similar things?
 
NH/AR are ORM (object relational mappers) frameworks that map entities to a database. the entities are defined by POCOs (plain old compiled objects).

Datasets are more like the POCOs than the NH/AR frameworks. Datasets come with baggage though. they are large objects, comparatively. they have many public members you may not need, which clutters the object.

POCOs only contain the code your provide. this makes for much more explicit objects.

for example. with a strongly typed dataset named Customer. there are mulitple ways to add a new Customer.
1. Customer.Rows.Add()
2. Customer.AddNewRow()
3. Customer.Rows.NewRow()
4. Customer.AddARowMyWay()

if you need to add behavior to a CustomerRow where is it added? How does a developer know the proper method to pick?

This also raises another issue. Does Customer have rows? probably not, rows are a database concept. you may have a collection of Customers though and you would add a customer to a collection of customers. Now we are getting into semantics. but this is important, because a behavior-centric system (Domain Driven Design) is defined by the domain. and the domain should use "ubiquitous language" to define objects and behavior. Simply put, the domain should reflect the business process.

there are many other reasons, which I'm finding difficult to put into words. At the end of the day I have found that POCOs are much easier to work with. And NH/AR makes database access a non-issue.



Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks jmackley for the post. However, I have not found any tutorial on the web which shows how to use the active record or nhibernate. ASP.NET has some nice tutorials explaining datasets, but there is nothing for nhibernate or active record in .NET.

Do you know of any?
 
google nhibernate or active record. there are lots of example. however they aren't like google examples. a good place to get started with NH or AR is the google groups. there is also an nhibernate faq blog which has good examples of getting started. and hibernate.org hosts both the java hibernate and .net nhibernate docs.

as a side note, when researching NH and AR you will be begin see other terms like unit testing, agile, ddd, tdd, ioc and other terms that MS tutorials do not usually talk about. these TLAs represent powerful concepts that create system which are coded drastically different than MS examples.

active record is built on top of nhibernate. it uses attributes instead of xml configuration. if you are using .net 3.5 there are 2 emerging projects which make NH that much more easy to use. Fluent.Nhibnerate which configures NH configuration using code rather than xml (which make refactoring that much easier). and LinqToNhibernate, which is just what it sounds like. it doesn't support all the crazy sql queries that NHibernate does, but I find that if your sql is that crazy it's a design flaw.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top