Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CommandBehavior.SchemaOnly
Message
 
 
À
30/07/2013 12:43:18
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:
01579464
Vues:
41
>>>>>>>>Hi Viv,
>>>>>>>>
>>>>>>>>If I change definition of the TableSchema class to be
>>>>>>>>
>>>>>>>>public class TableSchema 
>>>>>>>>{
>>>>>>>>
>>>>>>>>internal String TableName;
>>>>>>>>
>>>>>>>>public List<ColumnSchema> Columns = new List<ColumnSchema>();
>>>>>>>>
>>>>>>>>}
>>>>>>>>
>>>>>>>>then how would I retrieve column schema for particular column name ?
>>>>>>>
>>>>>>>
var columnSchema = Columns.Where(x => x.ColumnName == "Name").FirstOrDefault();
>>>>>>
>>>>>>Good idea! So, you think it's better than using dictionary, right?
>>>>>>
>>>>>>If so, I'll try to change to your code and use a List.
>>>>>
>>>>>Don't see much point in a Dictionary here. And IEnumerable might be better the List....
>>>>
>>>>A Dictionary should give close to O(1) look up time, whereas an IEnumerable will be O(n). Depending on the size of the list and how often its used, the speed difference is probably negligible. It is easy enough to create the Dictionary though:
>>>>
Dictionary<string, ColumnSchema> columnTypes;
>>>>
>>>>            using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.SchemaOnly))
>>>>            {
>>>>
>>>>                 columnTypes = (from DataRow r in reader.GetSchemaTable().AsEnumerable()
>>>>                                                  select new ColumnSchema
>>>>                                                      {
>>>>                                                          ColumnName = (string) r["ColumnName"],
>>>>                                                          ColumnSize = (Int32) r["ColumnSize"],
>>>>                                                          DbType = (SqlDbType) r["ProviderType"],
>>>>                                                          DataType = (Type) r["DataType"]
>>>>                                                      }).ToDictionary(cs=> cs.ColumnName);
>>>>            }
Fair point. Guess we don't know enough about the context in which the collection will be used. One downside of a Dictionary is that it makes it more difficult to access an item by anything other than the ColumnName?
>>
>>But in this context, I don't think the dicitonary is needed. A simple IEnumerable should suffice.
>
>Naomi stated she wanted to retrieve the ColumnSchema data by the column name. I would say that is more than enough justification for a dictionary.

Rob,

So, should I go back to Dictionary? Usually the number of columns for table no more than 250 columns.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform