EntityCollection from two related EntityBases (+generics)

Posts   
 
    
alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 19-Oct-2006 06:51:42   

Is it possible to get a parent object's collection if you only have a parent entity the EntityBase of the collection? Hopefully this bit of code will make sense..


Imports System
Imports System.Text
Imports System.Collections.Generic
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports SD.LLBLGen.Pro.ORMSupportClasses

Public Class EntityBaseJoiner(Of parentEntityType As EntityBase, collectionEntityType As EntityBase)
    Public Function JoinBases(ByVal parentEntity As parentEntityType) As EntityCollectionBase(Of collectionEntityType)
        ' Fill in the blanks
        Return Nothing
    End Function

End Class

<TestClass()> Public Class EntityBaseJoinerTests
    <TestMethod()> Public Sub EntitiesCanBeJoined()
        Dim joiner As New EntityBaseJoiner(Of UserEntity, EmailAddressEntity)
        Dim user As New UserEntity()

        Assert.IsTrue(joiner.JoinBases(user) = user.EmailAddresss)
    End Sub

End Class

Obviously I'm having trouble at the part where it says "Fill in the blank"... Maybe there's an easier way..

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 19-Oct-2006 07:00:55   

I'm afraid your question is not clear enough Please elaborate more.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 19-Oct-2006 09:32:40   

Isn't it better to use interfaces for this? (If I understand the question correctly) i.e IEntity and IEntityCollection

Frans Bouma | Lead developer LLBLGen Pro
alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 19-Oct-2006 18:20:15   

The test above explains exactly what I'm trying to do. It would take too long to explain further, and interfaces won't work. I'll trudge ahead with my workaround.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 19-Oct-2006 19:09:16   

If you join the entities inside a EntityCollection<IEntity> it doesn't need any effort. Otherwise you run into co-variance problems. (or I miss something in your example, which is possible, I didn't fully grasp what you're trying to do flushed )

Frans Bouma | Lead developer LLBLGen Pro