Saturday, December 27, 2008

Pramod Sadalage, has written an article on Behaviour Driven DB development. http://www.methodsandtools.com/archive/archive.php?id=78.

He writes about adding behaviour to the domain model and how that behaviour is translates into database objects, with tests. In the project I'm working on, which driven by a Web UI I use the UI behaviour to build the presenter and  through this add behaviour to the domain model. It's at the last stage that I add the persistance, through Nhibernate.

Saturday, December 27, 2008 11:20:26 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
 Thursday, January 24, 2008

Many web applications have a back end "admin" pages to manage tables in the database.  These pages exist solely to perform CRUD operations against a single table. Sometimes with a bit of validation.

It is tedious work if you have to create and write the same code  for each table and to maintain them. To make this task somewhat easier, there are solutions that look at the database structure, and generate the data access code and the asp.net pages.

The latest and greatest of them is ASP .Net Dynamic data. This uses LINQ to SQL for data access. Its quite easy to get a site up and running using this.

Mono Rail has an ActiveRecord scaffold.  This uses Castle ActiveRecord and Nhibernate to generate the scaffold. However, this doesn't generate the database to object model mapping automatically.  Classes that inherent from an ActiveRecord base have to be created first. Fields and relationships have to be defined in code. When this is done its all a breeze. Its a good way to get to grips with MonoRail.

 

Subsonic which I'm using on a project now, has two methods of operation. It has a set of scaffold controls which you can use on any asp.net pages to get CRUD functionality, and it also has the option to generate the asp.net pages and the data classes. The data classes generated by subsonic use the active record pattern too. The code generated by subsonic can be modified if you need to do so. After the code is generated these are normal asp.net pages to which you can add validation, combine with master pages etc..

Subsonic and Asp.Net dynamic data offer the quickest way to get up and running.  Subsonic and MonoRail offer the possibility to extend the application when things get more complex. The data classes generated can be reused when the application grows beyond a simple prototype or admin section.

Thursday, January 24, 2008 9:53:00 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
 Tuesday, June 26, 2007

I was playing with Redgate's SQL Dependency tracker yesterday. The balloon tree view sort of shows how modular the db design is. I'm working on a project where I'm implementing "pluggable" modules of functionality.

The two circular clusters at the top left corner are the db objects for the module I'm working on. The view shows how the cluster relates to the ASP .Net membership provider tables. The clusters which go diagonally across the view are the aspnet db objects.

image

Tuesday, June 26, 2007 9:31:11 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
 Saturday, November 25, 2006

The Object Data Source (ODS) helps you expose your business objects, to provide data to databound controls such as the GridView, DetailsView and many other data bound controls.

Compared to the other data sources like the DataTable and DataSet, the ODS does require some work to achieve the same functionality. The main advantage of the ODS is that it allows you to maintain your layers, without polluting your presentation layer with data code.

To start off,  drag and drop the ODS control to a web form. Set the TypeName property to the business object you want to work with. For example, if we have a BO named Employees in the TimeTracker namespace, this will be TimeTracker.Employee.

Selecting
 A common scenario is to display the a list of records. Say we want to display the list of all employees in a GridView. To retrieve the records, the Employee object needs a GetEmployees static method that will retrieve  all the employees from the DB.  Set the SelectMethod property of the ODS to GetEmployees. Now bind the ODS to the GridView just like any other data source.

At runtime the ODS uses reflection to find the GetEmployees method and invokes it.

Paging and filtering

Filtering Employee objects is as easy as adding a new method to your Employee object. If we want to select Employees by department, the Employee object should have a static method

GetEmployees(string department)

In the properties window of the ODS, add the department parameter to the SelectParameters collection. You can set a default value to it, and this is where things get real easy. You can bind the parameter to a control on your web form ( like a DropDownList) , a Session variable and even a query string parameter.  Adding  filtering functionality is simple as that. You can do the same programmatically by adding Parameters to the SelectParameters collection. Be sure to clear the collection before you add a parameter( or check if the parameter exists).

Paging is where working with the ODS gets a bit complicated. To enable paging ( in conjunction with the GridView) set the EnablePaging property to true. The Employee object too, needs to have methods to support paging.

When paging is enabled, the ODS calls the GetEmployee method with two extra parameters. by default the parameters are startRowIndex and maximumRows. These can be changed by setting the StartRowIndexParameterName and MaximumRowsParameterName properties.

Now we need a GetEmployees method with the signature like
GetEmployees(int startRowIndex,int maxiumRows)
To support filtering it will have to be GetEmployees(string department ,int startRowIndex,int maxiumRows)

The maximumRows parameter, will have the value of how many rows to display per page. This will have the value of the PageSize property of the GridView. The startRowIndex will contain the the index of the current page. This can be the starting row index of the current page of records. See here for more on how to pass these on to an SQL query.

In addition to this the ODS needs another method that is set by the SelectCountMethod property. This is invoked to find out the total number of rows available. So we need another static method in our Employee object. GetEmployeesCount() .If the total number of rows is 100, and you have a page size of 20. The GetEmployees count method should return 100, so that the ODS can tell the GridView, how many pager links to display. I usually return this as an out parameter from the stored procedure that retrieves the paged results.

Inserting, Editing and Deleting

Inserting, editing and deleting is pretty easy. All you will again is to have the appropriate static methods in the Employee object.
AddEmployee(Employee e)
UpdateEmployee(Employee e)
DeleteEmployee(Emplyee e).

Set the InsertMethod , UpdateMethod and DeleteMethod properties accordingly. All these method can be configured with parameters like the SelectMethod. However, setting the DataObjectTypeName property to the Employee object will reduce a lot of the hassle by passing Employee objects to the Add,Update and DeleteMethods.

Saturday, November 25, 2006 1:33:32 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
 Wednesday, December 28, 2005

While working with the System.Timers.Timer class last week, I found that the timer_elapsed method is not synchronized, i.e the event is fired without waiting for the completion of the previous invocation.

Say for example you have a method that pulls up the latest records from a table and do some processing. The timer event can fire while you are doing this processing and have still not marked the records as processed. The safe way is to wrap the code in the timer_elapsed event inside a lock statement.

Wednesday, December 28, 2005 10:36:32 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
 Thursday, July 28, 2005

The first step to migrate your SQL Server

Download here

"The Microsoft SQL Server 2005 Upgrade Advisor is a tool used by Database developers and administrators to analyze SQL Server 7.0 and SQL Server 2000 database servers in preparation for upgrading to SQL Server 2005. The Upgrade Advisor will allow users to analyze the configuration of their existing database services and database applications. As a result of this analysis, Upgrade Advisor will provide reports that identify deprecated features and necessary configuration changes that will impact their Database upgrade process. Upgrade Advisor will also provide links to documentation that describe these changes and necessary steps to complete the process."

 

Thursday, July 28, 2005 8:01:04 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
 Tuesday, March 22, 2005

http://www.devx.com/dotnet/Article/27297

Now if only they would release it !!.

The release date has slipped to the end of this year. I wish they would just release the runtime sooner or even backport some of the enhancements and bug fixes.

Tuesday, March 22, 2005 11:15:57 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  |