Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Looking for advice on how to search for a holiday
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01336267
Message ID:
01336271
Vues:
12
>I've just started looking into converting our VFP app over to .NET and have a question on how best to replicate a specific routine from our current app.
>
>We have a holiday table that contains records for each holiday, for each corresponding country in our country table. Right now, our routine accepts a date and an array of country codes that we loop through. For each country code in the loop, we seek the holiday table to see if the country code + date record exists. If so, then we have a holiday.
>
>For C#, I'm not sure which approach to use (i.e. arrays, datasets/rows, etc). I think it would be more efficient to send a select command to the database to see if any holiday records exist with a combination of the date and any of the passed countries - a record count > 0 would give me the result I need. I just don't know how to go about this since I'm a total n00b. ;)
>
>Any help to point me in the right direction would be greatly appreciated.
>
>Jon
______
Thinking aloud ...

Since there are not that many holidays in a year - apart from weekends - a List<T>  (or a HashSet<T>)would be fine to hold the holidays for a countryID
Lookup using Contains()

To hold the lists of the countries, a Dictionary<Int, List<T>> would be fine. 
You can find out whether the country is already in the dictionary using the TryGetValue(), 
 and if it is not in, add it to the dictionary (after a database select command)

So, it can be a sort of a cache, if the country is not needed, it will not be in the dictionary.  First time it is needed, add it to the dictionary

The lookup will be a lot faster than the select (open connection, select, close connection)
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform