IList IListSource.GetList() { EntityType rootEntityType = null; if (WrappedOwner.Entity != null) { EntitySet singleEntitySet = null; // if the collection is attached, we can use metadata information; otherwise, it is unavailable if (null != RelationshipSet) { singleEntitySet = ((AssociationSet)RelationshipSet).AssociationSetEnds[ToEndMember.Name].EntitySet; var associationEndType = (EntityType)((RefType)(ToEndMember).TypeUsage.EdmType).ElementType; var entitySetType = singleEntitySet.ElementType; // the type is constrained to be either the entitySet.ElementType or the end member type, whichever is most derived if (associationEndType.IsAssignableFrom(entitySetType)) { // entity set exposes a subtype of the association rootEntityType = entitySetType; } else { // use the end type otherwise rootEntityType = associationEndType; } } } return(ObjectViewFactory.CreateViewForEntityCollection(rootEntityType, this)); }
IList IListSource.GetList() { EntityType entityType = (EntityType)null; if (this.WrappedOwner.Entity != null) { if (this.RelationshipSet != null) { EntitySet entitySet = ((AssociationSet)this.RelationshipSet).AssociationSetEnds[this.ToEndMember.Name].EntitySet; EntityType elementType1 = (EntityType)((RefType)this.ToEndMember.TypeUsage.EdmType).ElementType; EntityType elementType2 = entitySet.ElementType; entityType = !elementType1.IsAssignableFrom((EdmType)elementType2) ? elementType1 : elementType2; } } return((IList)ObjectViewFactory.CreateViewForEntityCollection <TEntity>(entityType, this)); }