internal static TypeUsage ValidateNewEntityWithRelationships( EntityType entityType, IEnumerable <DbExpression> attributeValues, IList <DbRelatedEntityRef> relationships, out DbExpressionList validArguments, out ReadOnlyCollection <DbRelatedEntityRef> validRelatedRefs) { TypeUsage typeUsage = ArgumentValidation.ValidateNew(ArgumentValidation.CreateResultType((EdmType)entityType), attributeValues, out validArguments); if (relationships.Count > 0) { List <DbRelatedEntityRef> relatedEntityRefList = new List <DbRelatedEntityRef>(relationships.Count); for (int index = 0; index < relationships.Count; ++index) { DbRelatedEntityRef relationship = relationships[index]; EntityTypeBase elementType = TypeHelpers.GetEdmType <RefType>(relationship.SourceEnd.TypeUsage).ElementType; if (!entityType.EdmEquals((MetadataItem)elementType) && !entityType.IsSubtypeOf((EdmType)elementType)) { throw new ArgumentException(Strings.Cqt_NewInstance_IncompatibleRelatedEntity_SourceTypeNotValid, StringUtil.FormatIndex(nameof(relationships), index)); } relatedEntityRefList.Add(relationship); } validRelatedRefs = new ReadOnlyCollection <DbRelatedEntityRef>((IList <DbRelatedEntityRef>)relatedEntityRefList); } else { validRelatedRefs = new ReadOnlyCollection <DbRelatedEntityRef>((IList <DbRelatedEntityRef>) new DbRelatedEntityRef[0]); } return(typeUsage); }
internal static TypeUsage ValidateNewRow( IEnumerable <KeyValuePair <string, DbExpression> > columnValues, out DbExpressionList validElements) { List <KeyValuePair <string, TypeUsage> > columnTypes = new List <KeyValuePair <string, TypeUsage> >(); EnumerableValidator <KeyValuePair <string, DbExpression>, DbExpression, DbExpressionList> validator = ArgumentValidation.CreateValidator <KeyValuePair <string, DbExpression>, DbExpression, DbExpressionList>(columnValues, nameof(columnValues), (Func <KeyValuePair <string, DbExpression>, int, DbExpression>)((columnValue, idx) => { ArgumentValidation.CheckNamed <DbExpression>(columnValue, nameof(columnValues), idx); columnTypes.Add(new KeyValuePair <string, TypeUsage>(columnValue.Key, columnValue.Value.ResultType)); return(columnValue.Value); }), (Func <List <DbExpression>, DbExpressionList>)(expList => new DbExpressionList((IList <DbExpression>)expList))); validator.GetName = (Func <KeyValuePair <string, DbExpression>, int, string>)((columnValue, idx) => columnValue.Key); validElements = validator.Validate(); return(ArgumentValidation.CreateResultType((EdmType)TypeHelpers.CreateRowType((IEnumerable <KeyValuePair <string, TypeUsage> >)columnTypes))); }
internal static TypeUsage ValidateRefFromKey( EntitySet entitySet, DbExpression keyValues, EntityType entityType) { ArgumentValidation.CheckEntitySet((EntitySetBase)entitySet, nameof(entitySet)); ArgumentValidation.CheckType((EdmType)entityType); if (!TypeSemantics.IsValidPolymorphicCast((EdmType)entitySet.ElementType, (EdmType)entityType)) { throw new ArgumentException(Strings.Cqt_Ref_PolymorphicArgRequired); } TypeUsage resultType = ArgumentValidation.CreateResultType((EdmType)TypeHelpers.CreateKeyRowType((EntityTypeBase)entitySet.ElementType)); ArgumentValidation.RequireCompatibleType(keyValues, resultType, nameof(keyValues)); return(ArgumentValidation.CreateReferenceResultType((EntityTypeBase)entityType)); }
internal static TypeUsage ValidateNavigate( DbExpression navigateFrom, RelationshipEndMember fromEnd, RelationshipEndMember toEnd, out RelationshipType relType, bool allowAllRelationshipsInSameTypeHierarchy) { ArgumentValidation.CheckMember((EdmMember)fromEnd, nameof(fromEnd)); ArgumentValidation.CheckMember((EdmMember)toEnd, nameof(toEnd)); relType = fromEnd.DeclaringType as RelationshipType; ArgumentValidation.CheckType((EdmType)relType); if (!relType.Equals((object)toEnd.DeclaringType)) { throw new ArgumentException(Strings.Cqt_Factory_IncompatibleRelationEnds, nameof(toEnd)); } ArgumentValidation.RequireCompatibleType(navigateFrom, fromEnd, allowAllRelationshipsInSameTypeHierarchy); return(ArgumentValidation.CreateResultType(toEnd)); }
internal static TypeUsage ValidateNavigate( DbExpression navigateFrom, RelationshipType type, string fromEndName, string toEndName, out RelationshipEndMember fromEnd, out RelationshipEndMember toEnd) { ArgumentValidation.CheckType((EdmType)type); if (!type.RelationshipEndMembers.TryGetValue(fromEndName, false, out fromEnd)) { throw new ArgumentOutOfRangeException(fromEndName, Strings.Cqt_Factory_NoSuchRelationEnd); } if (!type.RelationshipEndMembers.TryGetValue(toEndName, false, out toEnd)) { throw new ArgumentOutOfRangeException(toEndName, Strings.Cqt_Factory_NoSuchRelationEnd); } ArgumentValidation.RequireCompatibleType(navigateFrom, fromEnd, false); return(ArgumentValidation.CreateResultType(toEnd)); }