internal static TypeUsage ValidateCreateRef( EntitySet entitySet, EntityType entityType, IEnumerable <DbExpression> keyValues, out DbExpression keyConstructor) { ArgumentValidation.CheckEntitySet((EntitySetBase)entitySet, nameof(entitySet)); ArgumentValidation.CheckType((EdmType)entityType, nameof(entityType)); if (!TypeSemantics.IsValidPolymorphicCast((EdmType)entitySet.ElementType, (EdmType)entityType)) { throw new ArgumentException(Strings.Cqt_Ref_PolymorphicArgRequired); } IList <EdmMember> keyMembers = (IList <EdmMember>)entityType.KeyMembers; EnumerableValidator <DbExpression, KeyValuePair <string, DbExpression>, List <KeyValuePair <string, DbExpression> > > validator = ArgumentValidation.CreateValidator <DbExpression, KeyValuePair <string, DbExpression>, List <KeyValuePair <string, DbExpression> > >(keyValues, nameof(keyValues), (Func <DbExpression, int, KeyValuePair <string, DbExpression> >)((valueExp, idx) => { ArgumentValidation.RequireCompatibleType(valueExp, keyMembers[idx].TypeUsage, nameof(keyValues), idx); return(new KeyValuePair <string, DbExpression>(keyMembers[idx].Name, valueExp)); }), (Func <List <KeyValuePair <string, DbExpression> >, List <KeyValuePair <string, DbExpression> > >)(columnList => columnList)); validator.ExpectedElementCount = keyMembers.Count; List <KeyValuePair <string, DbExpression> > keyValuePairList = validator.Validate(); keyConstructor = (DbExpression)DbExpressionBuilder.NewRow((IEnumerable <KeyValuePair <string, DbExpression> >)keyValuePairList); return(ArgumentValidation.CreateReferenceResultType((EntityTypeBase)entityType)); }
internal static void ValidateConstant(TypeUsage constantType, object value) { ArgumentValidation.CheckType(constantType, nameof(constantType)); EnumType type1; if (TypeHelpers.TryGetEdmType <EnumType>(constantType, out type1)) { Type clrEquivalentType = type1.UnderlyingType.ClrEquivalentType; if (clrEquivalentType != value.GetType() && (!value.GetType().IsEnum() || !ArgumentValidation.ClrEdmEnumTypesMatch(type1, value.GetType()))) { throw new ArgumentException(Strings.Cqt_Constant_ClrEnumTypeDoesNotMatchEdmEnumType((object)value.GetType().Name, (object)type1.Name, (object)clrEquivalentType.Name), nameof(value)); } } else { PrimitiveType type2; if (!TypeHelpers.TryGetEdmType <PrimitiveType>(constantType, out type2)) { throw new ArgumentException(Strings.Cqt_Constant_InvalidConstantType((object)constantType.ToString()), nameof(constantType)); } PrimitiveTypeKind primitiveTypeKind; if ((!ArgumentValidation.TryGetPrimitiveTypeKind(value.GetType(), out primitiveTypeKind) || type2.PrimitiveTypeKind != primitiveTypeKind) && (!Helper.IsGeographicType(type2) || primitiveTypeKind != PrimitiveTypeKind.Geography) && (!Helper.IsGeometricType(type2) || primitiveTypeKind != PrimitiveTypeKind.Geometry)) { throw new ArgumentException(Strings.Cqt_Constant_InvalidValueForType((object)constantType.ToString()), nameof(value)); } } }
internal static TypeUsage ValidateNewEmptyCollection( TypeUsage collectionType, out DbExpressionList validElements) { ArgumentValidation.CheckType(collectionType, nameof(collectionType)); if (!TypeSemantics.IsCollectionType(collectionType)) { throw new ArgumentException(Strings.Cqt_NewInstance_CollectionTypeRequired, nameof(collectionType)); } validElements = new DbExpressionList((IList <DbExpression>) new DbExpression[0]); return(collectionType); }
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)); }
internal static TypeUsage ValidateNew( TypeUsage instanceType, IEnumerable <DbExpression> arguments, out DbExpressionList validArguments) { ArgumentValidation.CheckType(instanceType, nameof(instanceType)); CollectionType type = (CollectionType)null; if (TypeHelpers.TryGetEdmType <CollectionType>(instanceType, out type) && type != null) { TypeUsage elementType = type.TypeUsage; validArguments = ArgumentValidation.CreateExpressionList(arguments, nameof(arguments), true, (Action <DbExpression, int>)((exp, idx) => ArgumentValidation.RequireCompatibleType(exp, elementType, nameof(arguments), idx))); } else { List <TypeUsage> expectedTypes = ArgumentValidation.GetStructuralMemberTypes(instanceType); int pos = 0; validArguments = ArgumentValidation.CreateExpressionList(arguments, nameof(arguments), expectedTypes.Count, (Action <DbExpression, int>)((exp, idx) => ArgumentValidation.RequireCompatibleType(exp, expectedTypes[pos++], nameof(arguments), idx))); } return(instanceType); }
internal static void CheckType(TypeUsage type) { ArgumentValidation.CheckType(type, nameof(type)); }
private static void CheckType(EdmType type) { ArgumentValidation.CheckType(type, nameof(type)); }