Ejemplo n.º 1
0
        static public Dictionary <string, SqlParameter> GetParameters(Guid dataID,
                                                                      tgProviderSpecificMetadata providerMetadata, tgColumnMetadataCollection columns)
        {
            lock (parameterCache)
            {
                if (!parameterCache.ContainsKey(dataID))
                {
                    // The Parameters for this Table haven't been cached yet, this is a one time operation
                    Dictionary <string, SqlParameter> types = new Dictionary <string, SqlParameter>();

                    SqlParameter param1;
                    foreach (tgColumnMetadata col in columns)
                    {
                        tgTypeMap typeMap = providerMetadata.GetTypeMap(col.PropertyName);
                        if (typeMap != null)
                        {
                            string    nativeType = typeMap.NativeType;
                            SqlDbType dbType     = Cache.NativeTypeToDbType(nativeType);

                            param1 = new SqlParameter(Delimiters.Param + col.PropertyName, dbType, 0, col.PropertyName);
                            param1.SourceColumn = col.Name;

                            switch (dbType)
                            {
                            case SqlDbType.BigInt:
                            case SqlDbType.Decimal:
                            case SqlDbType.Float:
                            case SqlDbType.Int:
                            case SqlDbType.Money:
                            case SqlDbType.Real:
                            case SqlDbType.SmallMoney:
                            case SqlDbType.TinyInt:
                            case SqlDbType.SmallInt:

                                param1.Size      = (int)col.CharacterMaxLength;
                                param1.Precision = (byte)col.NumericPrecision;
                                param1.Scale     = (byte)col.NumericScale;
                                break;

                            case SqlDbType.DateTime:

                                param1.Precision = 23;
                                param1.Scale     = 3;
                                break;

                            case SqlDbType.SmallDateTime:

                                param1.Precision = 16;
                                break;

                            case SqlDbType.Udt:

                                SetUdtTypeNameToAvoidMonoError(param1, typeMap);
                                break;
                            }
                            types[col.Name] = param1;
                        }
                    }

                    parameterCache[dataID] = types;
                }
            }

            return(parameterCache[dataID]);
        }