Exemplo n.º 1
0
        static public Dictionary <string, SqlParameter> GetParameters(tgDynamicQuerySerializable query)
        {
            tgMetadata meta = null;

            lock (parameterCache)
            {
                meta = query;

                if (!parameterCache.ContainsKey(meta.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 meta.Columns)
                    {
                        tgTypeMap typeMap = meta.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[meta.DataID] = types;
                }
            }

            return(parameterCache[meta.DataID]);
        }
Exemplo n.º 2
0
 static private void SetUdtTypeNameToAvoidMonoError(SqlParameter param, tgTypeMap typeMap)
 {
     param.UdtTypeName = typeMap.NativeType;
 }
Exemplo n.º 3
0
 static private void SetUdtTypeNameToAvoidMonoError(SqlParameter param, tgTypeMap typeMap)
 {
     param.UdtTypeName = typeMap.NativeType;
 }