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 3218848
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:34:33+00:00 2026-05-17T15:34:33+00:00

I posted up part of some code the other day but in doing so

  • 0

I posted up part of some code the other day but in doing so caused more confusion. This is my code.

if ( HttpContext.Current.Session != null )
{
                if ( HttpContext.Current.Session[ "CurrentLabourTransactions" ] != null )
                {
                    Collection<JCTransLabour> oJCTransLabours = null;

                    oJCTransLabours = (Collection<JCTransLabour>)HttpContext.Current.Session["CurrentLabourTransactions"];

                    if (Settings.ShowTodaysTransactionInApproval)
                        if (oJCTransLabours != null) return oJCTransLabours;


                    if (oJCTransLabours != null)
                    {
//oJCtransLabour contains alot of record
                        var oCurrentLabourTrans = (from clt in oJCTransLabours
                                                   where clt.TransactionDate.Date != DateTime.UtcNow
                                                   select clt);
//oCurrentLabourTrans is null.
                        return oCurrentLabourTrans as Collection<JCTransLabour>;
                    }
                }
            }
            return null;

When going into the final if statement there are a lot of transactions with different dates. It seems to although it always returns null records.

Thanks in advance for any help.

  • 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-17T15:34:34+00:00Added an answer on May 17, 2026 at 3:34 pm

    This line is the culprit:

    return oCurrentLabourTrans as Collection<JCTransLabour>;
    

    oCurrentLabourTrans is not a Collection<JCTransLabour>, and thus the as operation returns null, as expected. If you were to do this instead:

    return (Collection<JBTransLabour) oCurrentLabourTrans;
    

    the cast would fail and an InvalidCastException would be thrown. LINQ operators produce objects which implement IEnumerable<> directly; they do not automatically create collection and list objects.

    If you have to return a Collection<>, you can do this instead:

    return new Collection<JCTransLabour>(oCurrentLabourTrans.ToList());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code, what It returns is a list of some clients, but
i posted the other day with practice questions i was getting stuck with and
Basically this is a program which I take a text file with some code
This post is closely related to another one I posted some days ago .
UPDATE: I've posted the Renderer code below, since this code here doesn't seem to
I posted a related question to no response but here I'll be less narrow.
I posted a related but still different question regarding Protobuf-Net before, so here goes:
(first posted on google group but no response so assuming I should be posting
This is probably a noob question that I will get slated for but here
I have a table generated from some PHP code that lists a SMALL amount

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.