Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3800536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:54:30+00:00 2026-05-19T13:54:30+00:00

I have set of ‘codes’ Z that are valid in a certain time period.

  • 0

I have set of ‘codes’ Z that are valid in a certain time period.

Since I need them a lot of times in a large loop (million+) and every time I have to lookup the corresponding code I cache them in a List<>. After finding the correct codes, i’m inserting (using SqlBulkCopy) a million rows.

I lookup the id with the following code (l_z is a List<T>)

var z_fk = (from z in l_z
            where z.CODE == lookupCode &&
                  z.VALIDFROM <= lookupDate &&
                  z.VALIDUNTIL >= lookupDate 
            select z.id).SingleOrDefault();

In other situations I have used a Dictionary with superb performance, but in those cases I only had to lookup the id based on the code.

But now with searching on the combination of fields, I am stuck.

Any ideas? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:54:30+00:00Added an answer on May 19, 2026 at 1:54 pm

    Create a Dictionary that stores a List of items per lookup code – Dictionary<string, List<Code>> (assuming that lookup code is a string and the objects are of type Code).

    Then when you need to query based on lookupDate, you can run your query directly off of dict[lookupCode]:

    var z_fk = (from z in dict[lookupCode]
                where z.VALIDFROM <= lookupDate &&
                      z.VALIDUNTIL >= lookupDate 
                select z.id).SingleOrDefault();
    

    Then just make sure that whenever you have a new Code object, that it gets added to the List<Code> collection in the dict corresponding to the lookupCode (and if one doesn’t exist, then create it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have set of coordinates that need to be separated into groups that are close
I have set the time zone in /config/application.rb , and I expect all times
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set up an app that is registered for remote notifications. - (void)application:(UIApplication*)application
I have set up an asset host at assets.domain.com but it appears that cookies
I have set up cruisecontrol.net cs for my project that has a number of
I have set up an annotation that will be used to keep track of
I have set a header file's role in Xcode to private so that it
I have set up a WCF service that will accept both JSON and XML
I have set an onclick with a variable on a link that calls the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.