public Dictionary <IRelation, HashSet <object> > FindReferringEntities <T>( IList <T> storedEntities, IList <IRelationInternal> relations) where T : class { var result = new Dictionary <IRelation, HashSet <object> >(); for (int j = 0; j < relations.Count; j++) { IRelationInternal relation = relations[j]; HashSet <object> reffering = new HashSet <object>(); for (int i = 0; i < storedEntities.Count; i++) { foreach (object entity in relation.GetReferringEntities(storedEntities[i])) { reffering.Add(entity); } } result.Add(relation, reffering); } return(result); }
/// <summary> /// Creates a relation between two tables. /// </summary> /// <typeparam name="TPrimary"> /// The type of the entities of the primary table. /// </typeparam> /// <typeparam name="TPrimaryKey"> /// The type of the primary key of the entities of the primary table. /// </typeparam> /// <typeparam name="TForeign"> /// The type of the entities of the foreign table. /// </typeparam> /// <typeparam name="TForeignKey"> /// Type type of the foreign key of the foreign table. /// </typeparam> /// <param name="primaryIndex"> /// An IIndex that specifies the primary key. /// </param> /// <param name="foreignIndex"> /// An IIndex that specifies the foreign key. /// </param> /// <param name="convertForeignToPrimary"> /// A function to convert a foreign key to the corresponding primary key. /// </param> /// <param name="convertPrimaryToForeign"> /// A function to convert a primary key to the corresponding foreign key. /// </param> /// <returns> /// The relation. /// </returns> public Relation <TPrimary, TPrimaryKey, TForeign, TForeignKey> CreateRelation <TPrimary, TPrimaryKey, TForeign, TForeignKey>( IUniqueIndex <TPrimary, TPrimaryKey> primaryIndex, IIndex <TForeign, TForeignKey> foreignIndex, Func <TForeignKey, TPrimaryKey> convertForeignToPrimary, Func <TPrimaryKey, TForeignKey> convertPrimaryToForeign, RelationOptions relationOptions ) where TPrimary : class where TForeign : class { if (primaryIndex == null) { throw new ArgumentNullException("primaryIndex"); } if (foreignIndex == null) { throw new ArgumentNullException("foreignIndex"); } if (convertForeignToPrimary == null) { throw new ArgumentNullException("convertForeignToPrimary"); } if (convertPrimaryToForeign == null) { throw new ArgumentNullException("convertPrimaryToForeign"); } if (relationOptions == null) { // Use default relation options relationOptions = new RelationOptions(); } var result = new Relation <TPrimary, TPrimaryKey, TForeign, TForeignKey>( primaryIndex, foreignIndex, convertForeignToPrimary, convertPrimaryToForeign, relationOptions); IRelationInternal relation = result; relation.ValidateAll(); this.relationMapping[relation.PrimaryTable].Referring.Add(relation); this.relationMapping[relation.ForeignTable].Referred.Add(relation); this.relations.Add(relation); return(result); }
public void ValidateForeignKeys( IList <IRelationInternal> relations, Dictionary <IRelation, HashSet <object> > referringEntities) { for (int i = 0; i < relations.Count; i++) { IRelationInternal relation = relations[i]; foreach (object entity in referringEntities[relation]) { relation.ValidateEntity(entity); } } }