TypedList from EntityCollection

Posts   
 
    
MichielAlders avatar
Posts: 30
Joined: 01-Sep-2009
# Posted on: 17-Sep-2009 15:33:00   

Hi,

Not getting bored of me yet? simple_smile

Still the same Entities:

I have an entity (EC001) which has an 1:n relation with EC002 this entity has an 1:1 relation with EC003 and EC006.

EC002.Groep = EC003.Groep EC002.Item = EC006.Item

With a prefetch path I can select these in 1 go.

But I would like an overview in a datagrid with data from EC002, EC003 and EC006

In SQL this would look like:


select ec002.ordnr as [Order], ec002.fase as [Phase], ec003.omsch30_1 as [Groep], ec006.omsch30_1 as [Item], ec002.aantl as [Count] from ec002
    inner join ec003 on ec003.groep = ec002.groep
    inner join ec006 on ec006.item = ec002.item
where ec002.ordnr = '0000994501' and ec002.fase = '001'

But is there a way to do the following directly on my collection or do I have to go select this seperatly in my database.

I was thinking about a TypedView or TypedList but this also goes back to the SQL Server.

Thanks in advance

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 17-Sep-2009 22:03:10   

You can project an entity graph on to a hierarchical dataset or dictionary - see the documentation here http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/Adapter/gencode_usingcollectionclasses_adapter.htm#HierarchicalProjections

If you want it as a flat table then you will need to go back to the DB for a typed list/view...

Matt

MichielAlders avatar
Posts: 30
Joined: 01-Sep-2009
# Posted on: 18-Sep-2009 09:51:59   

I have tried this but doesn't give me the expected results:


        Dim itemsPerOrdersView As New List(Of ItemsPerOrder)()

        Dim classProjector As New DataProjectorToCustomClass(Of ItemsPerOrder)(itemsPerOrdersView)
        Dim projector As New List(Of IEntityPropertyProjector)()

        projector.Add(New EntityPropertyProjector(Ec002Fields.Ordnr, "Order"))
        projector.Add(New EntityPropertyProjector(Ec002Fields.Fase, "Phase"))
        projector.Add(New EntityPropertyProjector(Ec003Fields.Omsch301, "Group"))
        projector.Add(New EntityPropertyProjector(Ec006Fields.Omsch301, "Item"))
        projector.Add(New EntityPropertyProjector(Ec002Fields.Aantl, "Count"))

        obj.Ec002.DefaultView.CreateProjection(projector, classProjector)

        datagrid.DataSource = itemsPerOrdersView

'Custom Class
Public Class ItemsPerOrder

    Private _Order, _Phase, _Group, _Item As String
    Private _Count As Decimal

    Public Property Order() As String
        Get
            Return Me._Order
        End Get
        Set(ByVal value As String)
            Me._Order = value
        End Set
    End Property

    Public Property Phase() As String
        Get
            Return Me._Phase
        End Get
        Set(ByVal value As String)
            Me._Phase = value
        End Set
    End Property

    Public Property Group() As String
        Get
            Return Me._Group
        End Get
        Set(ByVal value As String)
            Me._Group = value
        End Set
    End Property

    Public Property Item() As String
        Get
            Return Me._Item
        End Get
        Set(ByVal value As String)
            Me._Item = value
        End Set
    End Property

    Public Property Count() As Decimal
        Get
            Return Me._Count
        End Get
        Set(ByVal value As Decimal)
            Me._Count = value
        End Set
    End Property

End Class

But itemsPerOrdersView.Count only has 1 row with only, Order, Phase and Count filled, Item and Group stay empty.

Maybe I'm missing something here.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 18-Sep-2009 10:57:26   

You should create 2 custom properties in the Ec002 entity class which read their values from the associated Ec003.Omsch301 and Ec006.Omsch301.

For the sake of the example, let's call them: Ec003_Omsch301 & Ec006_Omsch301. Then instead of:

projector.Add(New EntityPropertyProjector(Ec003Fields.Omsch301, "Group")) projector.Add(New EntityPropertyProjector(Ec006Fields.Omsch301, "Item"))

You should use:

projector.Add( New EntityPropertyProjector( new EntityProperty("Ec003_Omsch301"), "Group" ) )
projector.Add( New EntityPropertyProjector( new EntityProperty("Ec006_Omsch301"), "Item" ) )
MichielAlders avatar
Posts: 30
Joined: 01-Sep-2009
# Posted on: 18-Sep-2009 11:52:38   

Ah great! That works nicely.


    Partial Public Class Ec002Entity
        Inherits CommonEntityBase

        Public Property Ec003Omsch() As String
            Get
                Return Me.Ec003.Omsch301
            End Get
            Set(ByVal value As String)
                Me.Ec003.Omsch301 = value
            End Set
        End Property

        Public Property Ec006Omsch() As String
            Get
                Return Me.Ec006.Omsch301
            End Get
            Set(ByVal value As String)
                Me.Ec006.Omsch301 = value
            End Set
        End Property
    End Class

Returned the expected results. Thank you very much!

Just a question though:

How does the framework know that New EntityProperty("Ec003Omsch") is related to the EC003Omsch property in EC002. Does it cycle throughout all entities searching for the Ec003Omsch property?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 18-Sep-2009 13:23:11   

How does the framework know that New EntityProperty("Ec003Omsch") is related to the EC003Omsch property in EC002. Does it cycle throughout all entities searching for the Ec003Omsch property?

Because the projector is created from an EntityView of acollection of this entity.

obj.Ec002.DefaultView.CreateProjection(projector, classProjector)