internal NavigationProperty(NavigationProperty np) : base(np) { this.EntityType = np.EntityType; this.AssociationName = np.AssociationName; // ok for next two var to ref the base class collections because these should be shared. // and other code assumes that if the base class collection is updated then so will the subclass. this._fkNames = np._fkNames; this._invFkNames = np._invFkNames; }
private static void UpdateBaseProperties(StructuralType structuralType, StructuralType baseStructuralType) { baseStructuralType.DataProperties.ForEach(dp => { var newDp = new DataProperty(dp); structuralType.AddDataProperty(newDp); }); if (baseStructuralType.IsEntityType) { var entityType = (EntityType)structuralType; var baseEntityType = (EntityType)baseStructuralType; baseEntityType.NavigationProperties.ForEach(np => { var newNp = new NavigationProperty(np); entityType.AddNavigationProperty(newNp); }); } }
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); }
public void RemoveChildren(EntityKey parentEntityKey, NavigationProperty navProp) { var navChildrenList = GetNavChildrenList(parentEntityKey, false); if (navChildrenList == null) { return; } var ix = navChildrenList.IndexOf(nc => nc.NavigationProperty == navProp); if (ix != -1) { return; } navChildrenList.RemoveAt(ix); if (navChildrenList.Count == 0) { _map.Remove(parentEntityKey); } }
internal NavigationPropertyBuilder(EntityTypeBuilder <TEntity> etb, NavigationProperty np) { _etb = etb; NavigationProperty = np; }
public void AddChild(EntityKey parentEntityKey, NavigationProperty navProp, IEntity child) { var navChildren = GetNavChildren(parentEntityKey, navProp, true); navChildren.Add(child); }
public NavigationSet(IEntity parentEntity, NavigationProperty navigationProperty) { ((INavigationSet)this).ParentEntity = parentEntity; }