The EntitySpaces Community

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

Dataset functionality in esCollection?

Last post 09-01-2008, 4:47 AM by rotep. 9 replies.
Sort Posts: Previous Next
  •  08-27-2008, 4:21 AM 10957

    Dataset functionality in esCollection?

    Hi, I would like to implement some functionality that a normal .NET Dataset offers in a esCollection...

    The functionality would be creating custom columns which hold calculated values over the collection. After this i need to be able to create a esEntityCollectionView(of EntityColletion) over it... Is this possible with the EntityCollection? Here is a code snippet of how I would accomplish this with a dataset. I really have NO idea of how to do this with the esCollection....

    Code:
    Dim ddc1 As DataColumn = New DataColumn()
    ddc1.ColumnName = "maxWorkStop"
    ddc1.DataType = GetType(System.DateTime)
    ddc1.Expression = "max(child(workitems).Stop)"
    
    Dim ddc2 As DataColumn = New DataColumn()
    ddc2.ColumnName = "minWorkStart"
    ddc2.DataType = GetType(System.DateTime)
    ddc2.Expression = "min(child(workitems).Start)"
    
    Dim ddc3 As DataColumn = New DataColumn()
    ddc3.ColumnName = "maxTaskStop"
    ddc3.DataType = GetType(System.DateTime)
    ddc3.Expression = "max(Child(subtasks).maxWorkStop)"
    
    Dim ddc4 As DataColumn = New DataColumn()
    ddc4.ColumnName = "minTaskStart"
    ddc4.DataType = GetType(System.DateTime)
    ddc4.Expression = "min(Child(subtasks).minWorkStart)"
    
    dataSet1.Tables("Task").Columns.Add(ddc1)
    dataSet1.Tables("Task").Columns.Add(ddc2)
    dataSet1.Tables("Task").Columns.Add(ddc3)
    dataSet1.Tables("Task").Columns.Add(ddc4)
  •  08-27-2008, 4:47 AM 10959 in reply to 10957

    Re: Dataset functionality in esCollection?

    Okay, this is a wide topic. First let me say that EntitySpaces will not work with DataSets or create collections over mulitple DataTables (this is by design and I could go into my diatribe as to why but will spare you from it) he he. Here is a post in our FAQ forum about extended properties.

    Extended Properties

    Also, there is a protected member that you can access from your "Custom" classes called "Table", this is the DataTable, you can add columns and such with expression that way too. You can even add those expression columns and expose them as Extended properties.

     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-27-2008, 6:06 AM 10960 in reply to 10959

    Re: Dataset functionality in esCollection?

    Is it still possible to get an aggregate value in a column when the parent/child relationship is handled in a relation to the table itself (through a parentId field)?

    So if I have three fields:

    1. FieldId
    2. ParentId
    3. DateField

    Can I then get the maximum dateField value where the ParentId is the current FieldId? This isn't really ES anymore is it?

  •  08-27-2008, 6:35 AM 10962 in reply to 10960

    Re: Dataset functionality in esCollection?

    Am I doing something wrong here? I call the AddAggregateColumns function before the collection is loaded...

    Code:
    '===============================================================================
    '                     EntitySpaces(TM) by EntitySpaces, LLC
    '                 A New 2.0 Architecture for the .NET Framework
    '                          http://www.entityspaces.net
    '===============================================================================
    '                       EntitySpaces Version # 2008.1.0623.0
    '                       MyGeneration Version # 1.2.0.7
    '                       Date Generated       : 13-8-2008 13:01:07
    '-------------------------------------------------------------------------------
    
    Imports System
    Imports System.Collections.Generic
    Imports System.Text
    Imports System.Data
    
    Imports EntitySpaces.Interfaces
    
    Namespace BLL
    
    	Partial Public Class EpPlan 
            Inherits esEpPlan
    
            Protected Overrides Function GetLocalBindingProperties() As System.Collections.Generic.List(Of EntitySpaces.Core.esPropertyDescriptor)
                Dim props As New List(Of EntitySpaces.Core.esPropertyDescriptor)
                props.Add(New EntitySpaces.Core.esPropertyDescriptor(Me, "MinStart", GetType(DateTime)))
                props.Add(New EntitySpaces.Core.esPropertyDescriptor(Me, "MaxFinish", GetType(DateTime)))
                Return props
                'Return MyBase.GetLocalBindingProperties()
            End Function
    
            Public Property MinStart() As DateTime
                Get
                    Return CType(Me.GetColumn("Min_Start"), DateTime)
                End Get
                Set(ByVal value As DateTime)
                    Me.SetColumn("Min_Start", value)
                End Set
            End Property
    
            Public Property MaxFinish() As DateTime
                Get
                    Return CType(Me.GetColumn("Max_Finish"), DateTime)
                End Get
                Set(ByVal value As DateTime)
                    Me.SetColumn("Max_Finish", value)
                End Set
            End Property
    
            Public Sub AddAggregateColumns()
                Dim max As New DataColumn
                Dim min As New DataColumn
                max.ColumnName = "Max_Finish"
                max.Expression = "Max(Finish_Date)"
    
                min.ColumnName = "Min_Start"
                min.Expression = "Min(Start_Date)"
    
                Me.Table.Columns.Add(min)
                Me.Table.Columns.Add(max)
            End Sub
    	End Class
    
    End Namespace
    
  •  08-27-2008, 7:08 AM 10963 in reply to 10962

    Re: Dataset functionality in esCollection?

    You need to add custom columns after the collection is loaded actually. But still, I think there are better ways to do this. Did you know you can bring back fake or psuedo or calculated fields in our query API? It seems to me your working way to hard and creating all this customization starts to lose some of the power of ES?
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-28-2008, 1:41 AM 10993 in reply to 10963

    Re: Dataset functionality in esCollection?

    In my supplied example, if everything is databound, when you change a value in the 'Child' data, the aggregate column is also automatically updated.

    Are the fields created by the query API also updated dynamically without a roundtrip to the database?

     

    Edit:

    If I add the aggregate columns after the collection is loaded, then I receive an Null reference exception. It seems that the Table property in the EpPlan class is Null... So adding any columns is not possible...

     The addAggregateColumns function loops through the Entities in the collection, and calls AddAggregateColumns for every entity. The code for that is a few posts earlier...

    Does work (well, at least adding the columns does LOL):

    Code:
    Dim coll as new EpPlanCollection
    coll.addAggregateColumns()
    coll.LoadAll()

    Doesn't work:

    Code:
    Dim coll as new EpPlanCollection
    coll.LoadAll()
    coll.addAggregateColumns()
  •  08-29-2008, 1:27 AM 11031 in reply to 10993

    Re: Dataset functionality in esCollection?

    Ok let me rephrase as to what I'm trying to accomplish with a small example:

    The dataset looks like this:

    Code:
    | ID | PARENT_ID | START_DATE | FINISH_DATE |
    |  1 |      NULL |       NULL |        NULL |
    |  2 |         1 | 01-01-2008 |  01-10-2008 |
    |  3 |         1 | 01-10-2008 |  01-15-2008 |
    |  4 |         1 | 01-15-2008 |  01-21-2008 |
    |  5 |      NULL |       NULL |        NULL |
    |  6 |         5 | 02-01-2008 |  02-09-2008 |
    |  7 |         5 | 02-09-2008 |  02-12-2008 |
    |  8 |         5 | 02-12-2008 |  02-17-2008 |
    |  9 |         5 | 02-17-2008 |  02-25-2008 |
    | 10 |      NULL |       NULL |        NULL |
    | 11 |        10 | 03-01-2008 |  03-10-2008 |
    | 12 |        10 | 03-10-2008 |  03-11-2008 |
    | 13 |        10 | 03-11-2008 |  03-12-2008 |
    | 14 |        10 | 03-12-2008 |  03-13-2008 |

     

    I need to add two columns:

    1. Min_Start
    2. Max_Finish

    These columns should get the Min(START_DATE) and Max(FINISH_DATE) of the rows where the PARENT_ID is equal to the ID of the 'current-row'. This is the dataset that should be returned:

    Code:
    | ID | PARENT_ID | START_DATE | FINISH_DATE |  MIN_START | MAX_FINISH |
    |  1 |      NULL |       NULL |        NULL | 01-01-2008 | 01-21-2008 |
    |  2 |         1 | 01-01-2008 |  01-10-2008 |       NULL |       NULL |
    |  3 |         1 | 01-10-2008 |  01-15-2008 |       NULL |       NULL |
    |  4 |         1 | 01-15-2008 |  01-21-2008 |       NULL |       NULL |
    |  5 |      NULL |       NULL |        NULL | 02-01-2008 | 02-25-2008 |
    |  6 |         5 | 02-01-2008 |  02-09-2008 |       NULL |       NULL |
    |  7 |         5 | 02-09-2008 |  02-12-2008 |       NULL |       NULL |
    |  8 |         5 | 02-12-2008 |  02-17-2008 |       NULL |       NULL |
    |  9 |         5 | 02-17-2008 |  02-25-2008 |       NULL |       NULL |
    | 10 |      NULL |       NULL |        NULL | 03-01-2008 | 03-13-2008 |
    | 11 |        10 | 03-01-2008 |  03-10-2008 |       NULL |       NULL |
    | 12 |        10 | 03-10-2008 |  03-11-2008 |       NULL |       NULL |
    | 13 |        10 | 03-11-2008 |  03-12-2008 |       NULL |       NULL |
    | 14 |        10 | 03-12-2008 |  03-13-2008 |       NULL |       NULL |

     

    Now here's the catch (i think):

    When I change the FINISH_DATE value of Row 14 to 03-29-2008 (In a databound DataGridView), I need the MAX_FINISH of row 10 to be instantly changed to 03-29-2008 too...

  •  09-01-2008, 12:44 AM 11061 in reply to 11031

    Re: Dataset functionality in esCollection?

    Nobody?
  •  09-01-2008, 3:01 AM 11064 in reply to 11061

    Re: Dataset functionality in esCollection?

    Well, If you edit it and then reload the grid it should automatically changed by your query isn't it?
  •  09-01-2008, 4:47 AM 11065 in reply to 11064

    Re: Dataset functionality in esCollection?

    I need it to be instantly changed. a re-query is not an option since this will affect performance dramatically...

    toch bedankt ;-)

View as RSS news feed in XML