1 //---------------------------------------------------------------------
2 // <copyright file="ViewCellRelation.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
8 //---------------------------------------------------------------------
10 using System.Collections.Generic;
11 using System.Data.Mapping.ViewGeneration.Structures;
13 using System.Data.Common.Utils;
16 namespace System.Data.Mapping.ViewGeneration.Validation
19 /// Represents a relation signature that lists all projected
20 /// slots of two cell queries in a cell after projection. So if
21 /// SPerson1.Disc is present in the cellquery (and part of the where
22 /// clause) but not in the projected slots, it is missing from a ViewCellRelation
24 internal class ViewCellRelation : CellRelation
28 // effects: Creates a view cell relation for "cell" with the
29 // projected slots given by slots -- cellNumber is the number of the
30 // cell for debugging purposes
31 // Also creates the BasicCellRelations for the left and right cell queries
32 internal ViewCellRelation(Cell cell, List<ViewCellSlot> slots, int cellNumber)
37 // We create the basiccellrelations passing this to it so that we have
38 // a reference from the basiccellrelations to this
39 m_cell.CQuery.CreateBasicCellRelation(this);
40 m_cell.SQuery.CreateBasicCellRelation(this);
45 private Cell m_cell; // The cell for which this relation exists
46 private List<ViewCellSlot> m_slots; // Slots projected from both cell queries
52 get { return m_cell; }
58 // requires: slot corresponds to a slot in the corresponding
60 // effects: Given a slot in the corresponding basicCellRelation,
61 // looks up the slot in this viewcellrelation and returns it. Returns
62 // null if it does not find the slot in the left or right side of the viewrelation
63 internal ViewCellSlot LookupViewSlot(MemberProjectedSlot slot)
65 // CHANGE_[....]_IMPROVE: We could have a dictionary to speed this up
66 foreach (ViewCellSlot viewSlot in m_slots)
68 // If the left or right slots are equal, return the viewSlot
69 if (ProjectedSlot.EqualityComparer.Equals(slot, viewSlot.CSlot) ||
70 ProjectedSlot.EqualityComparer.Equals(slot, viewSlot.SSlot))
78 protected override int GetHash()
80 // Note: Using CLR-Hashcode
81 return m_cell.GetHashCode();
82 // We need not hash the slots, etc - cell should give us enough
83 // differentiation and land the relation into the same bucket
86 internal override void ToCompactString(StringBuilder builder)
88 builder.Append("ViewRel[");
89 m_cell.ToCompactString(builder);
90 // StringUtil.ToSeparatedStringSorted(builder, m_slots, ", ");