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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:02:57+00:00 2026-05-24T05:02:57+00:00

I use the following query to get a result set var overlaps = from

  • 0

I use the following query to get a result set

var overlaps = from s in db.signups
               join u in db.users on new { userid = s.userid } equals new     { userid = u.studentid }
               join a in db.activities on new { activityid = s.activityid } equals new { activityid = a.id }
               where
                    s.userid != Convert.ToInt32(Request.Cookies["studentid"].Value) &&
                      (from signups in db.signups
                         where
                               signups.userid == Convert.ToInt32(Request.Cookies["studentid"].Value)
                             select new
                             {
                                 signups.activityid
                             }).Contains(new { s.activityid })
                        orderby
                          u.studentid
                        select new
                        {
                            a.name,
                            u.firstname,
                            u.lastname,
                            u.studentid,
                            u.email
                        };

I’m pretty new to LINQ so I actually wrote the Sql and then used Linqer to generate the LINQ, so if this can be done more efficiently then please let me know. Having said that, this is not the problem.

The problem is that when I do

foreach(var overlap in overlaps)
{
    //do something
}

it throws the object reference not set error. This is being run in an MVC 3 application.

However, when this is run in a Console application, it runs without issue; it just returns no results. I’ve tried using DefaultIfEmpty but just can’t find anything that addresses how to use this with anonymous types.

So
… is my approach correct?
If not, what should I do differently?

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-24T05:02:57+00:00Added an answer on May 24, 2026 at 5:02 am

    I don’t know if this is your problem, but your join syntax is really weird.

    You don’t have to build anonymous types here, just compare directly.

    join u in db.users on s.userid equals u.studentid
    join a in db.activities on s.activityid equals a.id
    

    Same with this:

    select new
    {
        signups.activityid
    }).Contains(new { s.activityid })
    

    Can be just:

    select signups.activityid).Contains(s.activityid)
    

    And why in the world do you want to redo all the work to convert the cookie parameter to an int over and over?

    var studentId = Convert.ToInt32(Request.Cookies["studentid"].Value);
    //use this instead now in the query, dont repeat yourself
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the following query to get the highest id of a set of
I use the following to get a list of project files that need to
i have the following code for search from database show return result to the
I have some following set of data from where I want to select Top
Consider the following use of template template parameters... #include <iostream> template <typename X> class
I use the following statement prepared and bound in ODBC: SELECT (CASE profile WHEN
I use the following code to create countdowns in Javascript. n is the number
I use the following for a jQuery link in my <script> tags: http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js Is
Let me use the following example to explain my question: public string ExampleFunction(string Variable)
If I use the following code I lose the ability to right click on

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.