internal static List <MemberProjectedSlot> GetKeySlots( IEnumerable <MemberProjectedSlot> slots, MemberPath prefix) { EntitySet entitySet = prefix.EntitySet; List <ExtentKey> keysForEntityType = ExtentKey.GetKeysForEntityType(prefix, entitySet.ElementType); return(MemberProjectedSlot.GetSlots(slots, keysForEntityType[0].KeyFields)); }
internal ErrorLog.Record VerifyKeysPresent( Cell ownerCell, Func <object, object, string> formatEntitySetMessage, Func <object, object, object, string> formatAssociationSetMessage, ViewGenErrorCode errorCode) { List <MemberPath> memberPathList = new List <MemberPath>(1); List <ExtentKey> extentKeyList = new List <ExtentKey>(1); if (this.Extent is EntitySet) { MemberPath prefix = new MemberPath(this.Extent); memberPathList.Add(prefix); EntityType elementType = (EntityType)this.Extent.ElementType; List <ExtentKey> keysForEntityType = ExtentKey.GetKeysForEntityType(prefix, elementType); extentKeyList.Add(keysForEntityType[0]); } else { AssociationSet extent = (AssociationSet)this.Extent; foreach (AssociationSetEnd associationSetEnd in extent.AssociationSetEnds) { AssociationEndMember associationEndMember = associationSetEnd.CorrespondingAssociationEndMember; MemberPath prefix = new MemberPath((EntitySetBase)extent, (EdmMember)associationEndMember); memberPathList.Add(prefix); List <ExtentKey> keysForEntityType = ExtentKey.GetKeysForEntityType(prefix, MetadataHelper.GetEntityTypeForEnd(associationEndMember)); extentKeyList.Add(keysForEntityType[0]); } } for (int index = 0; index < memberPathList.Count; ++index) { MemberPath prefix = memberPathList[index]; if (MemberProjectedSlot.GetKeySlots(this.GetMemberProjectedSlots(), prefix) == null) { ExtentKey extentKey = extentKeyList[index]; string message; if (this.Extent is EntitySet) { string userString = MemberPath.PropertiesToUserString(extentKey.KeyFields, true); message = formatEntitySetMessage((object)userString, (object)this.Extent.Name); } else { string name = prefix.RootEdmMember.Name; string userString = MemberPath.PropertiesToUserString(extentKey.KeyFields, false); message = formatAssociationSetMessage((object)userString, (object)name, (object)this.Extent.Name); } return(new ErrorLog.Record(errorCode, message, ownerCell, string.Empty)); } } return((ErrorLog.Record)null); }
/// <summary> /// Given the <paramref name="prefix" />, determines the slots in <paramref name="slots" /> that correspond to the entity key for the entity set or the /// association set end. Returns the list of slots. Returns null if even one of the key slots is not present in slots. /// </summary> /// <param name="prefix"> corresponds to an entity set or an association end </param> internal static List <MemberProjectedSlot> GetKeySlots(IEnumerable <MemberProjectedSlot> slots, MemberPath prefix) { // Get the entity type of the hosted end or entity set var entitySet = prefix.EntitySet; Debug.Assert(entitySet != null, "Prefix must have associated entity set"); var keys = ExtentKey.GetKeysForEntityType(prefix, entitySet.ElementType); Debug.Assert(keys.Count > 0, "No keys for entity?"); Debug.Assert(keys.Count == 1, "Currently, we only support primary keys"); // Get the slots for the key var keySlots = GetSlots(slots, keys[0].KeyFields); return(keySlots); }
// effects: Returns an error record if the keys of the extent/associationSet being mapped are // present in the projected slots of this query. Returns null // otherwise. ownerCell indicates the cell that owns this and // resourceString is a resource used for error messages internal ErrorLog.Record VerifyKeysPresent( Cell ownerCell, Func <object, object, string> formatEntitySetMessage, Func <object, object, object, string> formatAssociationSetMessage, ViewGenErrorCode errorCode) { var prefixes = new List <MemberPath>(1); // Keep track of the key corresponding to each prefix var keys = new List <ExtentKey>(1); if (Extent is EntitySet) { // For entity set just get the full path of the key properties var prefix = new MemberPath(Extent); prefixes.Add(prefix); var entityType = (EntityType)Extent.ElementType; var entitySetKeys = ExtentKey.GetKeysForEntityType(prefix, entityType); Debug.Assert(entitySetKeys.Count == 1, "Currently, we only support primary keys"); keys.Add(entitySetKeys[0]); } else { var relationshipSet = (AssociationSet)Extent; // For association set, get the full path of the key // properties of each end foreach (var relationEnd in relationshipSet.AssociationSetEnds) { var assocEndMember = relationEnd.CorrespondingAssociationEndMember; var prefix = new MemberPath(relationshipSet, assocEndMember); prefixes.Add(prefix); var endKeys = ExtentKey.GetKeysForEntityType( prefix, MetadataHelper.GetEntityTypeForEnd(assocEndMember)); Debug.Assert(endKeys.Count == 1, "Currently, we only support primary keys"); keys.Add(endKeys[0]); } } for (var i = 0; i < prefixes.Count; i++) { var prefix = prefixes[i]; // Get all or none key slots that are being projected in this cell query var keySlots = MemberProjectedSlot.GetKeySlots(GetMemberProjectedSlots(), prefix); if (keySlots == null) { var key = keys[i]; string message; if (Extent is EntitySet) { var keyPropertiesString = MemberPath.PropertiesToUserString(key.KeyFields, true); message = formatEntitySetMessage(keyPropertiesString, Extent.Name); } else { var endName = prefix.RootEdmMember.Name; var keyPropertiesString = MemberPath.PropertiesToUserString(key.KeyFields, false); message = formatAssociationSetMessage(keyPropertiesString, endName, Extent.Name); } var error = new ErrorLog.Record(errorCode, message, ownerCell, String.Empty); return(error); } } return(null); }