.Net Data Provider Overview
Summary
This is a high level summary of the basic .Net API’s for interacting with a database. This includes a short description of each and how they relate to each other. As a developer with mainly a Java and PHP background I was unclear about how ADO.Net related to OleDb and I had no idea what was meant by the term “.Net Data Provider”. I created this because the msdn documentation is HEAVILY focused on ADO.Net and does not give a clear picture of how the many namespaces, interfaces, and classes interact. Please add comments to correct or enlighten. Note at this time the relation of .Net Providers to Nhiberante, LINQ to SQL, and Entity Framework is not covered in this post.
.Net Data Provider
- http://msdn.microsoft.com/en-us/library/a6cd7c08(v=VS.71).aspx
- A .NET Framework data provider is used for connecting to a database, executing commands, and retrieving results. Those results are either processed directly, or placed in an ADO.NET DataSet.
What that actually means is that a .Net Data Provider implements the interfaces defined in the System.Data namespace. - A .Net Data Provider is similar to a JDBC driver in Java
- http://en.wikipedia.org/wiki/Java_Database_Connectivity
System.Data
- http://msdn.microsoft.com/en-us/library/system.data.aspx
- This page contains text that makes you believe that ADO.Net is the CORE part of .Net data access, however the reality is that ADO.Net is the highest level of data access and is built upon the .Net Data Providers that implement the interfaces in the System.Data.
- In my opinion it almost seems like microsoft is trying to hide how database connections work, so that users are trapped using controls provided by visual studio.
- This namesapce contains the Interfaces that need to be defined by ALL .Net Data Providers
- Core Interfaces
- IDbConnection
- IDbCommand
- IDataAdapter
- IDataReader
Four examples of System.Data Implementations
- The below namespaces include classes that implement the core “.Net Data Provider” interfaces defined in System.Data
|
System.Data.SqlClient |
System.Data.OleDb |
System.Data.Odbc |
IBM.Data.DB2.iSeries |
|
|
http://msdn.microsoft.com/en-us/library/system.data.oledb.aspx |
http://msdn.microsoft.com/en-us/library/system.data.odbc.aspx |
http://www-03.ibm.com/systems/i/software/access/windows/dotnet/index.html |
|
Core Classes
|
Core Classes
|
Core Classes
|
Core Classes
|
ADO.Net
- http://msdn.microsoft.com/en-us/library/27y4ybxw(v=VS.71).aspx
- ADO.Net is a database query and manipulation API built on top of the basic .Net Data Provider classes. ADO.Net focuses on disconnected, multi-tier database interaction. In my opinion the core ADO.Net classes should be in a separate namespace like System.Data.ADO just for the sake of clarity.
- Core Classes
- DataSet
- DataTable
- DataColumn
- DataRelation
Strange Loop 2010 – Early Bird Registration
The early bird registration is about to end for the Strange Loop 2010 conference. This is the second year of the conference. The first year was awesome, hopefully they can only make it better.
Go to the site to see the speaker list, because it’s too long to list here.
http://strangeloop2010.com/speakers?
Early bird registration for Strange Loop is open until 8/6/10. Don’t miss out – sign up now for just $150 through Aug. 6th.
Prices:
- Early bird – $150 (till Aug 6th)
- Regular – $190 (till Oct. 1st)
- Late – $250
Strange Loop 2009 posts
http://blog.codehangover.com/strange-loop-2009-day-1/
http://blog.codehangover.com/strange-loop-2009-day-2/
php
NHibernate 2 Beginner’s Guide – Book Review
Finally someone has written an in depth beginners book for nhibernate. Nhibernate 2.0 Beginners Guide written by Aaron Cure is just that and more. Wow do I sound like a car salesman. I was a little disappointed when I read Nhibernate In Action last year, because it was more of a reference than a tutorial. This book is definitely what the title states, which is a beginners guide. The book contains step by step examples of how to find, setup, and use nhibernate. I highly recommend this book to anyone wanting to learn nhibernate. By the way I think all .netters should do just that.
Pros
- love the beginning paragraphs
- In simple terms, NHibernate does all the database work, and we reap all the benefits! Instead of writing reams of SQL statements or creating stored procedures that “live” in a different place than our code, we can have all of our data access logic contained within our application.
With a few simple “tricks” that we’ll discuss in Chapter 4, Data Cartography, not only will our queries be effective, but they will also be validated by the compiler. Therefore, if our underlying table structure changes, the compiler will alert us that we need to change our queries!
- In simple terms, NHibernate does all the database work, and we reap all the benefits! Instead of writing reams of SQL statements or creating stored procedures that “live” in a different place than our code, we can have all of our data access logic contained within our application.
- starts slow, which is perfect for a “beginners” book. lots of hand holding and explanations of basics. this is truly meant for somehow with no experience with ORMs.
- clearly shows you how to use log4net! great bonus in a nhibernate book.
- briefly mentions all the major players in the nhibernate world, which is great for demonstrating options
- Examples: fluent nhibernate, nhibernate.burrow, castle, spring ioc, etc.
Cons
- book uses basic aspx pages with custom controls in the examples. I firmly suggest ASP.Net MVC over webforms. But it may be too much to learn at one time if you aren’t familiar with either nhib or MVC. So learn one first and then learn the other. You won’t regret it.
- most examples are in c# and vb.net. that’s good or bad depending on your opinion of vb.net.
- No HQL examples. All query examples use the Criteria class. This isn’t totally bad especially for beginners, but HQL should have at least been mentioned.
Chapter Notes
- chapter 1
- clearly denotes which version of nhib the book uses and where to get it
- Even explains the nhib release verbiage of “generally available”
- shows basic examples of mapping file and how it relates to POCOs. Good stuff for a ORM newbie.
- clearly denotes which version of nhib the book uses and where to get it
- chapter 2
- good advice for designing your database in logical way that avoids data duplication.
- clear steps to download and setup a database using sql server express
- Does mention that nhib works in almost any database, however all the book examples use sql server express
- nice explanation of how tables relate to your classes
- great introduction to OTM, MTO, MTM, and OTO relationships
- good summary of left joins and how joins matter in queries for the different relationship types
- chapter 3
- starts creating a simple class library application. clear steps and good examples.
- even addresses the somewhat hated nullable types and how to handle database columns that need to be mapped to types that can be null.
- chapter 4
- nice explanation of what mapping means in terms of ORM software and how it functions as the glue that binds your objects to the database.
- summary and examples of the most common used mapping types
- gives examples of two mapping styles
- xml
- lists the two main complaints which are.. 1) too much xml 2) xml files are not compiled, so you don’t find bugs until run time.
- provides great tip of adding the hibernate XSD to your project so that visual studio will provide code completion for you and validate your mapping files.
- important info about how to make sure the xml mapping files are compiled into your dll
- fluent nhibernate
- short example given that shows how using the “side” project http://fluentnhibernate.org/ can work without the xml mapping files.
- pro is that mappings have to be compiled, so bugs/typos are found earlier
- xml
- chapter 5
- creates console application to test the nhib code
- shows step by step how to add references to the nhib dlls that you need to download
- good definition of what a nhib session is and how it relates to an actual database session
- chapter 6
- why you should and how to use log4net with your nhib project
- excellent and thorough tutorial for using log4net
- chapter 7
- nhib config details
- mentions how easy it is to change databases by simply changing one config line
- shows how to config nhib in an app.config or web.config
- chapter 8
- provides example of Singleton DOA pattern
- shows example of using a structure that holds all the column/property names for a class/entity. this is done so that the column names in the structure can be used in criteria queries. all this effort is done to avoid run time exceptions. seems like a waste of time to me because you if you don’t update your structure every time your db is updated then you will still get runtime errors.
- query examples using Criteria (at this point all examples have been using Criteria, none in HQL)
- chapter 9
- in depth examples showing how to create custom controls to display data retrieved using nhibernate
- chapter 10
- shows how to implement the login controls with nhibernate
- chapter 11
- covers 11 code generation tools used to limit manual boiler plate coding. I actually hadn’t heard of many of the ones listed. Great bonus chapter.
- nhib-gen, mygeneration, NGen NHibernate Code Generator, and T4 hbm2net seem promising
- these tools create everything from POCOs to DAOs to services.
