コード例 #1
0
 protected SqlCallParameterBase(ProcedureName procedureName, ProcedureParameter parameter, ParameterDirection direction, bool nullable, bool isEnumerable)
 {
     if (parameter == null) {
         throw new ArgumentNullException("parameter");
     }
     parameterName = parameter.ParameterName.Value;
     if (direction == ParameterDirection.ReturnValue) {
         throw new ArgumentOutOfRangeException("direction");
     }
     this.direction = direction;
     if (parameter.ParameterTypeName.IsQualified || (!knownDbTypes.TryGetValue(parameter.ParameterTypeName.Name.Value, out sqlType))) {
         sqlType = isEnumerable ? SqlDbType.Structured : SqlDbType.Udt;
     } else {
         TypeNameWithPrecision typeNameEx = parameter.ParameterTypeName.Name as TypeNameWithPrecision;
         if (typeNameEx != null) {
             switch (sqlType) {
             case SqlDbType.Binary:
             case SqlDbType.VarBinary:
             case SqlDbType.Char:
             case SqlDbType.VarChar:
             case SqlDbType.NChar:
             case SqlDbType.NVarChar:
                 size = (int)typeNameEx.Precision;
                 break;
             }
         }
     }
     this.nullable = nullable;
     if (direction == ParameterDirection.Input) {
         if (parameter.Output) {
             throw new InvalidOperationException(string.Format("The {0} OUTPUT argument requires an out parameter in {1}", parameterName, procedureName));
         }
     } else {
         if (!parameter.Output) {
             throw new InvalidOperationException(string.Format("An out parameter requires argument {0} to be OUTPUT in {1}", parameterName, procedureName));
         }
         if (sqlType == SqlDbType.Structured) {
             throw new NotSupportedException(string.Format("Table valued argument {0} must be READONLY in {1}", parameterName, procedureName));
         }
     }
 }
コード例 #2
0
 public SqlCallParameterInfo(ISerializationTypeInfoProvider serializationTypeInfoProvider, ParameterInfo param, ProcedureName procedureName, ProcedureParameter script, ISerializationTypeMappingProvider typeMappingProvider)
     : base(procedureName, script, GetParameterDirection(param), GetParameterNullable(param), GetParameterEnumerable(param))
 {
     parameterInfo = param;
     if (SqlType == SqlDbType.Structured) {
         Type structuredType;
         if (!param.ParameterType.TryGetIEnumerableElementType(out structuredType)) {
             throw new ArgumentException("The given parameter must implement IEnumerable<> in order to be used as SQL structured parameter");
         }
         CreateTypeAsTableStatement createTableTypeScript;
         if (!AssemblyInventory.Get(param.Member.DeclaringType.Assembly).TryFind(script.ParameterTypeName.Name.Value, out createTableTypeScript)) {
             throw new ArgumentException(string.Format("The given structured parameter table type {0} cannot be found in the inventory", script.ParameterTypeName));
         }
         IDictionary<string, SqlColumnInfo> columnInfos;
         ISerializationTypeInfo info = serializationTypeInfoProvider.GetSerializationTypeInfo(structuredType);
         if (info.SimpleConverter != null) {
             string columnName = createTableTypeScript.TableDefinitions.OfType<TableColumnDefinition>().First(d => d.ColumnDefinition is TypedColumnDefinition).ColumnName.Value;
             columnInfos = new Dictionary<string, SqlColumnInfo>(1);
             columnInfos.Add(columnName, new SqlColumnInfo(typeMappingProvider.GetMapping(structuredType), columnName, info.SimpleConverter));
         } else {
             columnInfos = typeMappingProvider.GetMapping(structuredType).Columns;
             Attribute[] mappingAttributes = Attribute.GetCustomAttributes(param, typeof(SqlMappingAttribute), true);
             if ((mappingAttributes != null) && (mappingAttributes.Length > 0)) {
                 IDictionary<string, SqlColumnInfo> mappedColumnInfos = new Dictionary<string, SqlColumnInfo>(columnInfos);
                 foreach (SqlMappingAttribute mappingAttribute in mappingAttributes) {
                     mappedColumnInfos[mappingAttribute.TableTypeColumn] = columnInfos[mappingAttribute.SqlColumn];
                 }
                 columnInfos = mappedColumnInfos;
             }
         }
         structuredSchema = new StructuredParameterSchema(createTableTypeScript, columnInfos);
     }
     #warning Maybe implement more type compatibility checks for arguments here
     //			if ((sqlType == SqlDbType.Udt) && string.IsNullOrEmpty(arg.UserDefinedTypeName)) {
     //				userDefinedTypeName = SqlSerializationTypeMapping.GetClrUserDefinedTypeName(parameter.ParameterType, arg);
     //			}
 }
コード例 #3
0
 public SqlCallParameterConstant(ProcedureName procedureName, ProcedureParameter parameter, object value)
     : base(procedureName, parameter, ParameterDirection.Input, value == null, false)
 {
     this.value = value;
 }