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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:08:14+00:00 2026-06-15T00:08:14+00:00

When using LINQ to Entities how do you test for the object to have

  • 0

When using LINQ to Entities how do you test for the object to have no result?
For example, the following query will return no result if the custid has no order history BUT the page will still load, it just won’t have a gridview because there is no datasource for it to bind to.

Dim result = From c In ctx.orders
                 Where c.CustomerId = custId
          Join prod In ctx.products On prod.Id Equals c.ProductId
        Select New With
        {c.OrderDate,
         c.PurchaseOrderNumber,
         prod.description,
         c.ProductPrice,
         c.ProductQty}

How do you test the object for no result? I want to test for that to supply different markup to the page if no result is returned. Obviously I’ve tried If result = vbNull, also tried Is Nothing, those don’t work. The other problem is when using this query in a Try Catch block, even when no result is returned it does not catch an exception, I’m guessing it doesn’t see that as an error.

  • 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-06-15T00:08:15+00:00Added an answer on June 15, 2026 at 12:08 am

    You can use Any() like so:

    Dim hasElements As Boolean = result.Any();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on the following LINQ query: public void GetAuditRuleAgencyRecords(IEnumerable<Entities.AuditRule> rules) { using (LinqModelDataContext
I'm using LINQ-to-Entities. Using the following query: var x = from u in context.Users
I'm using linq to entities (C# Winforms) and my database has the following structure:
Using LINQ to Entities with Entity Framework and C#: I have a method that
I'm using Entity Framework 4.2 (EntityFramework.dll v4.0.30319) Code First and have a LINQ query
I'm trying to rewrite a SQL query in LINQ to Entities. I'm using LINQPad
Using Linq to Entities, I have an IQueryable<T> and want to add another WHERE
Using linq to entities i am connecting to a database, the database has tables
I'm using linq to entities(EF). I have a constructor which takes 4 string parameters.
For a project using LINQ to Entities 4.0, I have a setting in which

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.