More in this section

Forums / Developing with Sitefinity / Fun with Nolics

Fun with Nolics

3 posts, 0 answered
  1. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    03 Nov 2007
    Link to this post
    I am not sure if everyone is enjoying Nolics as much as I am (that sounds pretty lame) so I thought I would post on one of the neat things that you can do with the Nolics.

    Below is a Nolics .dbclass file for hierarchal related category data. Notice how you can linked parentID to the same table instead of a standard GUID field. This allows you to have a strongly typed reference to the parent category after a query. Also notice how you can have a relation to the ChildArray in the same table. This allows you to get an object reference to each of the child objects. Most know that you can do this for related tables, but applying this feature for hierarchal related data in the same table I thought was nice touch.

    The only downside to Nolics database objects for hierarichal data is that the RadTree doesn't recognize the relationship between the parentID and ID so you have to populate your RadTreeView using the recursive method, but that's not too slow.

    If anyone else has any Nolics tips I would love to hear about them.

     
    dbclass Category [TableName="category",WebBinder=true]   
    {  
      primary key guid ID[AutoGenGUID=True];  
      string Name;  
      string UniqueName;  
      string Description;  
      int Order;  
      bool Active;  
      bool IsRoot;  
      string HeadDescription;  
      string HeadKeywords;  
      link Category ParentCategory_lnk: guid ParentID;  
      relation Category(ParentCategory_lnk)[] ChildArray;      
      relation ProductCategoryLink [] ProductArray;   
      version long Version;  
      created date CreatedDate;  
      modified date ModifiedDate;   
    }  
     
    namespace queries;  
     
    query GetCategory for Category [ProcedureName="getcategory",OrderBy="CreatedDate DESC",WebBinder=true]  
    {  
        guid ID ?= ID;  
        string Name ?like Name;  
        string UniqueName ?= UniqueName;  
        string Description ?like Description;  
        guid ParentID ?= ParentID;  
        bool IsRoot [Nullable = True] ?= IsRoot;  
        bool Active [Nullable = True] ?= Active;  

    Sincerely,

    Ben
  2. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    03 Nov 2007
    Link to this post
    And here is how you can use this Category.dbclass to populate a RadTreeView based on the example at telerik.com.

    Private Sub BindData()  
            Try  
                Dim item As Category  
                Dim query As New queries.GetCategory  
                query.Active = True 
                query.LoadAll()  
     
                For Each item In query  
                    If item.ParentID = Nothing Then  
                        Dim node As RadTreeNode  
                        node = CreateNode(item, False)  
                        tvCategory.Nodes.Add(node)  
                        RecursivelyPopulate(item, node)  
                    End If  
                Next  
            Catch ex As Exception  
     
            End Try  
        End Sub  
     
    Private Function CreateNode(ByVal item As Category, ByVal bExpand As Boolean) As RadTreeNode  
            Try  
                Dim node As New RadTreeNode  
     
                node.Text = item.Name  
                node.Value = item.UniqueName  
                node.NavigateUrl = _productListURL + "?categoryId=" + item.UniqueName  
                node.Expanded = bExpand 
                Return node  
            Catch ex As Exception  
                Return Nothing  
            End Try  
        End Function  
        Private Sub RecursivelyPopulate(ByVal item As Category, ByVal node As RadTreeNode)  
            Try  
                Dim childItem As Category  
                For Each childItem In item.ChildArray  
                    Dim childNode As RadTreeNode = CreateNode(childItem, False)  
                    node.Nodes.Add(childNode)  
                    RecursivelyPopulate(childItem, childNode)  
                Next  
            Catch ex As Exception  
     
            End Try  
        End Sub 

    Enjoy,

    Ben
  3. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    04 Nov 2007
    Link to this post
    Ben, thanks a ton for posting this!

    Nolics (and ORMs) are new to me and I'm proceedingly s-l-o-w-l-y.  It's hard for me to let go of the SQL.   :)   I'm making progress though.

    Examples like this help a ton!

    Gabe
    ===============
Register for webinar
3 posts, 0 answered