The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Sorting Attached Entitys

Last post 07-08-2007, 6:06 PM by David.Parsons. 1 replies.
Sort Posts: Previous Next
  •  07-08-2007, 11:37 AM 3708

    Sorting Attached Entitys

    I had the need to use a join so I got a collection from a relationship table and loop through it to populate what I needed from the parent table. The collection is feeding the data to a combo box in a winform. The issue i'm having now is sorting the information. I would also ask if working with the relationship table in this manner was a good way to go.
      "SELECT ID, NAME FROM Reasons WHERE ID IN (SELECT ID FROM ReasonsToSourceType WHERE SourceTypeID = @SourceTypeID)"  
      Relationship Diagram
    Code:
    1    	Partial Public Class ActivityTrackerReasonsCollection
    2    		Inherits esActivityTrackerReasonsCollection
    3    		
    4            Public Sub New()
    5    			' It is recommended that you do not put code in here
    6            End Sub		
    7            Public Sub LoadbySourceType(ByVal SourceTypeID As Integer)
    8                Dim ColRel As New ActivityTrackerSourceTypestoReasonsCollection
    9                Dim rel As ActivityTrackerSourceTypestoReasons
    10               ColRel.Query.LoadbySourceType(SourceTypeID)
    11   
    12               Dim Chooseone As New ActivityTrackerReasons
    13               Chooseone.Id = -1
    14               Chooseone.Name = "<Choose Resolution>"
    15               Me.AttachEntity(Chooseone)
    16   
    17               For Each rel In ColRel
    18                   Dim SingleEntity As New ActivityTrackerReasons
    19                   SingleEntity.LoadByPrimaryKey(rel.ReasonID)
    20                   Me.AttachEntity(SingleEntity)
    21               Next
    22           End Sub
    23   	End Class
    
    Code:
    1    	Partial Public Class ActivityTrackerSourceTypestoReasonsQuery
    2    		Inherits esActivityTrackerSourceTypestoReasonsQuery
    3    		
    4            Public Sub New()
    5    			' It is recommended that you do not put code in here
    6            End Sub
    7    
    8            Public Function LoadbySourceType(ByVal ID As Integer) As Boolean
    9                Me.Select(Me.ReasonID)
    10               Me.Where(Me.SourceTypeID.Equal(ID))
    11               Me.Load()
    12           End Function
    13   
    14   	End Class
    
  •  07-08-2007, 6:06 PM 3716 in reply to 3708

    Re: Sorting Attached Entitys

    It's hard to make recommendations without knowing your full requirements, but my first thought is that a ComboBox may not be the best way to present a Many to Many to the user. You might take a look at the Many to Many Example in the EntitySpacesDemo to see if it offers a solution.

    A few other possibilities:

    1) The WinForm ComboBox has a Sorted property which defaults to false. Set it to true.

    2) Set the Sort property on the collection after populating it.
       collection.Sort = "LastName ASC"

    3) Add an ORDERBY to the SELECT you are using for your JOIN.


    David Neal Parsons
    www.entityspaces.net
View as RSS news feed in XML