Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CommandBehavior.SchemaOnly
Message
De
30/07/2013 15:16:12
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01579375
Message ID:
01579477
Vues:
48
This message has been marked as a message which has helped to the initial question of the thread.
>>I think Rob's right in that if there are a lot of lookups by ColumnName then Dictionary would be faster. OTOH is you wanted, say a list ofcolumns of int Types then IEnumerable would be better....
>
>In my case I output all columns for a table. I normally access column by column name. I already switched to List. Should I switch back to dictionary?
>
>My current classes:
>
>
> /// <summary>
>   /// Column schema - some properties
>   /// </summary>
>    public class ColumnSchema
>    {
>       public String ColumnName { get; set; }
>       public Type DataType { get; set; }
>       public SqlDbType DbType { get; set; }
>       public Int32 ColumnSize { get; set; }
>       public Int16 Precision { get; set; }
>       public Int16 Scale { get; set; }
>       public Boolean IsIdentity { get; set; }
>      
>       /// <summary>
>       /// default constructor
>       /// </summary>
>       public ColumnSchema()
>       {
>       }
>
>       public ColumnSchema(String columnName, Type dataType, SqlDbType dbType, Int32 columnSize, Int16 precision, Int16 scale, Boolean isIdentity)
>       {
>          ColumnName = columnName;
>          DataType = dataType;
>          DbType = dbType;
>          ColumnSize = columnSize;
>          Precision = precision;
>          Scale = scale;
>          IsIdentity = isIdentity;
>       }
>    }
>
>   /// <summary>
>   /// TableSchema class - has a list of columns
>   /// </summary>
>    public class TableSchema
>    {
>        internal String TableName;
>        internal List<ColumnSchema> Columns = new List<ColumnSchema>();
>
>        public TableSchema(String table, List<ColumnSchema> columnsList)
>        {
>            TableName = table;
>            Columns = columnsList;
>        }
>       /// <summary>
>       /// Returns column's schema
>       /// </summary>
>       /// <param name="columnName"></param>
>       /// <returns></returns>
>        internal ColumnSchema GetColumnSchema(String columnName)
>        {
>           var columnSchema = Columns.Where(x => x.ColumnName == columnName).FirstOrDefault();
>
>            return columnSchema;
>        }
>
>        internal Type GetColumnType(String columnName)
>        {
>           var columnSchema = GetColumnSchema(columnName);
>           if (columnSchema==null)
>                return null;
>
>            return columnSchema.DataType;
>        }
>
>        internal SqlDbType? GetColumnDbType(String columnName)
>        {
>           var columnSchema = GetColumnSchema(columnName);
>           if (columnSchema == null)
>              return null;
>
>           return columnSchema.DbType;
>        }
>    }
As per Rob, if you only need to access the collection via the ColumnName (and do it often) then Dictionary will be the best option.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform