internal ChildRowCollection(Row parentRow, ChildRelation relation, Table childTable, IEnumerable <Row> childRows) : base(childRows.ToList()) { ParentRow = parentRow; ChildTable = childTable; Relation = relation; }
//Returns an internal ChildRowCollection with AddRow //and RemoveRow methods to allow ForeignKeyColumn to //update the collection when it changes. internal ChildRowCollection ChildRows(ChildRelation relation, bool forceCreate) { if (relation == null) { throw new ArgumentNullException("relation"); } if (Table == null) { throw new InvalidOperationException("Child relations cannot be used on detached rows"); } if (Table.Context == null) { throw new InvalidOperationException("Child relations can only be used for tables inside a DataContext"); } ChildRowCollection retVal; if (!childRelations.TryGetValue(relation, out retVal) && forceCreate) { var childTable = Table.Context.Tables[relation.ChildSchema]; if (childTable == null) { throw new InvalidOperationException("Cannot find " + relation.ChildSchema.Name + " table"); } retVal = new ChildRowCollection( this, relation, childTable, relation.ChildColumn.HasIndex ? childTable.GetIndex(relation.ChildColumn).GetOrNull(this) ?? Enumerable.Empty <Row>() : childTable.Rows.Where(r => r[relation.ChildColumn] == this)); childRelations.Add(relation, retVal); } return(retVal); }
///<summary>Gets the child rows in the specified child relation.</summary> ///<returns>A ChildRowCollection containing a live view of the child rows.</returns> public IChildRowCollection <Row> ChildRows(ChildRelation relation) { return(ChildRows(relation, true)); }
internal void OnRelationRemoved(ChildRelation relation) { childRelations.Remove(relation); typedChildRelations.Remove(relation); } //Won't throw if not found