@@ -1779,6 +1779,9 @@ var EntityType = (function () {
17791779 var orderDetailType = em1.metadataStore.getEntityType("OrderDetail");
17801780 var companyNameProp2 = orderDetailType.getProperty("Order.Customer.CompanyName");
17811781 // companyNameProp === companyNameProp2
1782+ This method can also walk a property path to return a property in a subtype
1783+ @example
1784+ var exciseTaxProp = orderDetailType.getProperty("Order/InternationalOrder.ExciseTax");
17821785 @method getProperty
17831786 @param propertyPath {String}
17841787 @param [throwIfNotFound=false] {Boolean} Whether to throw an exception if not found.
@@ -1797,9 +1800,23 @@ var EntityType = (function () {
17971800 var parentType = this ;
17981801 var key = useServerName ? "nameOnServer" : "name" ;
17991802 var props = propertyNames . map ( function ( propName ) {
1803+ // split for casting entity property to subtype
1804+ var nameParts = propName . split ( "/" ) ;
1805+ propName = nameParts [ 0 ] ;
1806+ var subtype = nameParts [ 1 ] ;
1807+
18001808 var prop = __arrayFirst ( parentType . getProperties ( ) , __propEq ( key , propName ) ) ;
18011809 if ( prop ) {
18021810 parentType = prop . isNavigationProperty ? prop . entityType : prop . dataType ;
1811+
1812+ // if subtype is specified, use that next
1813+ if ( subtype ) {
1814+ // change parentType to subtype
1815+ parentType = parentType . getSubtype ( subtype , throwIfNotFound ) ;
1816+ if ( ! parentType ) {
1817+ ok = false ;
1818+ }
1819+ }
18031820 } else if ( throwIfNotFound ) {
18041821 throw new Error ( "unable to locate property: " + propName + " on entityType: " + parentType . name ) ;
18051822 } else {
@@ -1819,8 +1836,20 @@ var EntityType = (function () {
18191836 return fn ( propName ) ;
18201837 } ) ;
18211838 } else {
1822- propNames = this . getPropertiesOnPath ( propertyPath , false , true ) . map ( function ( prop ) {
1823- return prop . nameOnServer ;
1839+ var parentType = this ;
1840+ propNames = this . getPropertiesOnPath ( propertyPath , false , true ) . map ( function ( prop , index , arr ) {
1841+ parentType = prop . isNavigationProperty ? prop . entityType : prop . dataType ;
1842+ var propName = prop . nameOnServer ;
1843+
1844+ // try getting the next property's parent
1845+ var nextParentType = ( arr [ index + 1 ] || { parentType : parentType } ) . parentType ;
1846+
1847+ if ( nextParentType !== parentType ) {
1848+ // we can assume this to be a subtype, use the next property's parent
1849+ propName = __formatString ( "%1/%2.%3" , propName , nextParentType . namespace , nextParentType . shortName ) ;
1850+ }
1851+
1852+ return propName ;
18241853 } ) ;
18251854 }
18261855 return propNames . join ( delimiter ) ;
@@ -1834,6 +1863,22 @@ var EntityType = (function () {
18341863 return new EntityKey ( this , keyValues ) ;
18351864 } ;
18361865
1866+ /**
1867+ Returns the subtype of this type by short name down thru the hierarchy.
1868+
1869+ @method getSubtype
1870+ @param shortName [String]
1871+ @param [throwIfNotFound=false] {Boolean} Whether to throw an exception if not found.
1872+ **/
1873+ proto . getSubtype = function ( shortName , throwIfNotFound ) {
1874+ throwIfNotFound = throwIfNotFound || false ;
1875+ var subtype = __arrayFirst ( this . getSelfAndSubtypes ( ) , __propEq ( "shortName" , shortName ) ) ;
1876+ if ( ! subtype && throwIfNotFound ) {
1877+ throw new Error ( __formatString ( "The entityType '%1' is not a subtype of entityType '%2'" , shortName , this . name ) ) ;
1878+ }
1879+ return subtype ;
1880+ } ;
1881+
18371882 proto . _updateTargetFromRaw = function ( target , raw , rawValueFn ) {
18381883 // called recursively for complex properties
18391884 this . dataProperties . forEach ( function ( dp ) {
0 commit comments