コード例 #1
0
ファイル: EntityType.cs プロジェクト: GioviQ/breeze.sharp
        private bool UpdateNavigationProperty(NavigationProperty np)
        {
            var entityType = np.EntityType;

            var invNp = entityType.NavigationProperties.FirstOrDefault(altNp => {
                // Can't do this because of possibility of comparing a base class np with a subclass altNp.
                //return altNp.associationName === np.associationName
                //    && altNp !== np;
                // So use this instead.
                return(altNp.AssociationName == np.AssociationName &&
                       (altNp.Name != np.Name || altNp.EntityType.Name != np.EntityType.Name));
            });

            np.Inverse = invNp;
            if (invNp == null)
            {
                // unidirectional 1-n relationship
                np.InvForeignKeyProperties.ForEach(invFkProp => {
                    invFkProp.IsForeignKey = true;
                    var invEntityType      = (EntityType)np.ParentType;

                    invFkProp.InverseNavigationProperty = invEntityType.NavigationProperties.FirstOrDefault(np2 => {
                        return(np2.InvForeignKeyNames.IndexOf(invFkProp.Name) >= 0 && np2.EntityType == invFkProp.ParentType);
                    });
                });
            }

            // sets navigation property: relatedDataProperties and dataProperty: relatedNavigationProperty
            np.ForeignKeyProperties.ForEach(dp => {
                if (np.EntityType.KeyProperties.Count == 1)
                {
                    dp.RelatedNavigationProperty = np;
                }
                else
                {
                    dp.IsForeignKey = true;
                    np.EntityType.UpdateInverseForeignKeyProperties(dp);
                    np.UpdateWithRelatedDataProperty(dp);
                }
            });

            return(true);
        }