Well you prabably heard about MyGeneration by now if you are a regular BloggingAbout.Net reader. If you haven't go and download it now here.
I am currently in the process of rewriting a web application and I am completely doing away with the old DAL. Instead I am using the dOOdad architecture that comes with MyGeneration.
Here are some of the advantages I found so far....
- About 40 % less code in the presentation layer ! ( So there is less to review as well )
- The code is much more readable.
- The Stored Procedures in the database all have a Uniform Name
- It's Faster ! ( probably my old DAL wasn't as fast as I thought)
- 0 lines of code in my DAL. Everything is handled in the generated Classes.
- I guess an overall code reduction of 70%
- Even the Dynamic SQL is handled in the correct SQL way (optimizing it for successive executes)
- Doing away with a lot of Stored procedures that would return a very specific subset
And since it's a Web application you can do really nice stuff to the sort orders as well. Like the following....
If Not IsPostBack Then
Dim PubType As String = Request.QueryString.Item("PubType")
If PubType = Nothing Then
MyPublications.LoadAll() ' Load Them all
Else
MyPublications.Where.PublicationType.Value = PubType
MyPublications.Query.Load() ' Load the specific subset
End If
' Set Sort order
MyPublications.Sort = MyPublications.ColumnNames.PublicationDate + " DESC"
' Add to cache
Cache.Remove("Publications")
Cache.Insert("Publications", MyPublications)
BindGrid()
End If
Then when you click on a header you can do stuff like....
Private Sub dgPublications_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgPublications.SortCommand
' Get from the cache
MyPublications = Cache.Get("Publications")
' Set new sortexpression but keep results sorted on date
MyPublications.Sort = e.SortExpression + " , " + MyPublications.ColumnNames.PublicationDate + " DESC"
MyPublications.Rewind()
' Add to cache, but first delete the old one
Cache.Remove("Publications")
Cache.Insert("Publications", MyPublications)
BindGrid()
End Sub
You don't have to requey anything just set the sortcommand on the Entity, rewind the stuff and bind it again....
And you could do the same with filters although I haven't used that yet....
Also a deletecommand on the datagrid is easy as .....
Dim key As Integer = CInt(dgPublications.DataKeys(e.Item.ItemIndex).ToString())
Dim DelPublication As New Publications
DelPublication.LoadByPrimaryKey(Key)
DelPublication.MarkAsDeleted()
DelPublication.Save()
Response.Redirect("Start.aspx?PageID=ListPublications")
Really easy ! No forgotten connetcions or stuff like that. and the code is still easy to read.......
Also note the Difference between the following....
MyPublications.LoadByPrimaryKey(Key) ' Load the specific record
And
MyPublications.Where.PublicationType.Value = PubType
MyPublications.Query.Load() ' Load the specific subset
And
MyPublications.LoadAll() ' Load them all !
This made me do away with a couple of stored procedures........... Reducing the SQL Code as well.....