DAL Requirement Database independent DAL implementation should allow easy swap of database servers (SQL Server to Oracle) Configurable DAL selection can be controlled by configuration file Example: connection string should be in web.config file or app.config Persisting the Application Object Model Save the info in memory (object-oriented data) to disk (relational data) Example: In windows app, department chair saves his non-finalized version of course planning for next quarter.
DAL responsibilities In one transaction: 1. Add new course 2. Update pre-req 3. Delete old course
DAL - Transaction Management Keep track of all significant changes to the applications data that occur in a unit of work A unit of work is a logical (business) transaction that groups a number of database calls Atomic - one indivisible operation Consistency - no data corruption when failure occurs Isolated - Other operation can not see the modified data until completion Durability - successful or failed transaction notification
ADO.NET A data provider is a set of ADO.NET classes (libraries) Allows you to access a specific database Execute SQL commands Retrieve data A bridge between your application and database Classes that make up a data provider include: Connection Establish a connection to database Command Execute SQL commands and stored procedures DataReader fast, read-only, forward-only access from a query DataAdapter Fill a DataSet*** More on DataSet next
Review question What are the DAL’s major responsibilities? Why would you need transactions in the DAL? Why do you need try catch in DAL? What .NET library will you be using for DAL? Difference between DataSet and DataAdapter? What is assert.equal() method used for? Why do you need to have sql connection string in the app.config when running unit tests?
Demo of VS 2010 O/RM Student info & enrollment in stored procedure Students Enrollment in DAL OR/M between database and DAL Run unit test in DAL
Your assignment for next week Set up your solution to include the following "Class Library" projects DataAccessLayer project BusinessLayer project BusinessObjects project Develop the Data Access Layer code (CRUD) Unit Tests for your DAL