Otis wrote:
You use the 2-class scenario, so you should use the My* entities everywhere and not the other ones. That way the hierarchies are all of the correct types.
This is because of the following:
MyCustomerEntity is subtype of CustomerEntity, and MyOrderEntity is subtype of OrderEntity. 'Orders' in MyCustomerEntity... has to hide Orders in CustomerEntity, because that is of type EntityCollection<OrderEntity>, not of type EntityCollection<MyOrderEntity> (as it is part of CustomerEntity), and List<string> isn't a subtype of List<object>
Thank you for your response. I understand the usage now. Although I would like to use the MyTbl.. versions of the entities, it is clear that when adding to the MyTbl* entities to collections of type TblEntity that the AddRange method will only accept the Tbl collection.
As shown in the example below I can add MyTbl* entities to the related collection if I iterate across the IEntity2 entries of a MyTbl* collection, but I can't AddRange with a collection of different types - I understand that now.
This works
'Add a test entry
Me.ModifyGroupLists.Add(New RegisterEntity.MyTblGroupModifyEntity())
'Add range of EntityCollection(Of TblGroupModifyEntity)
mDocumentEntity.TblGroupModify.AddRange(Me.ModifyGroups)
'Add items from EntityCollection(Of MyTblGroupModifyEntity)
For Each entity As IEntity2 In Me.ModifyGroupLists
mDocumentEntity.TblGroupModify.Add(entity)
Next
Where
ModifyGroups is EntityCollection(Of TblGroupModifyEntity)
ModifyGroupLists is EntityCollection(Of MyTblGroupModifyEntity)
mDocumentEntity.TblGroupModify is EntityCollection(Of TblGroupModify)
but this does not work
'Add a test entry
Me.ModifyGroupLists.Add(New RegisterEntity.MyTblGroupModifyEntity())
'Can't do this!
'Add range of EntityCollection(Of MyTblGroupModifyEntity)
mDocumentEntity.TblGroupModify.AddRange(Me.ModifyGroupLists)
'This does not work either
'Add items from EntityCollection(Of MyTblGroupModifyEntity)
For Each entity As MyTblGroupModifyEntity In Me.ModifyGroupLists
mDocumentEntity.TblGroupModify.Add(entity)
Next
My final question is shouldn't the AddRange simply iterate the interface entities to achieve the same result?