Awesome Dynamic SQL generation....
Hmmm,
Played around a littlebit with the dOOdad architecture of MyGeneration. Besides a lot of nice features there is also the the dynamic query feature.... Let me show what I mean.....
' See if it is in cache
Mymenu = Cache.Get("DefaultMenu")
If Mymenu Is Nothing Then
'get the default Menu
Dim MyMenuID As New MenuID
MyMenuID.Where.MenuDescription.Value = "DefaultMenu"
MyMenuID.Query.Load()
'Now get the MenuEntries for the menu !
Mymenu = New MenuData
Mymenu.Where.MenuID.Value = MyMenuID.ID
Mymenu.Where.MenuID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal
' Only those rows that we are Authenticated to see
Mymenu.Where.AuthenticationLevel.Value = Session("AuthenticationLevel")
Mymenu.Where.AuthenticationLevel.Operator = MyGeneration.dOOdads.WhereParameter.Operand.LessThanOrEqual
Mymenu.Query.AddOrderBy(Mymenu.ColumnNames.MenuOrder, ,myGeneration.dOOdads.WhereParameter.Dir.ASC)
Mymenu.Query.Load()
'Cache this menu.
Cache.Insert("DefaultMenu", Mymenu)
End If
'Bind to the grid
MenuGrid.DataSource = Mymenu.DefaultView
MenuGrid.DataBind()
In the blue piece of code we set some where parameters and add a sortorder. Everything resulted in the following query beeing executed :
SELECT * FROM [MenuData] WHERE [MenuID] = @MenuID1 AND [AuthenticationLevel] <= @AuthenticationLevel2 ORDER BY [MenuOrder] ASC
And this is a really nice query, nothing wrong with that !. I just was surprised how easy it was !.