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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:02:02+00:00 2026-05-30T11:02:02+00:00

I am a bit new to LINQ and to Entity Framework, so rather simple

  • 0

I am a bit new to LINQ and to Entity Framework, so rather simple SQL queries are causing me a headache. I have a user input screen that allows them to select input values and the resulting query is dependent on which values the user entered. The resulting query groups up the results to present a list of unique customers

Simplified table design – A customer can be in many states

Customer
CustomerId
Name
JoinDate

State
StateId
CustomerId

So the user has to enter a customer name on the screen to fire off the query, but the state is an optional field, so my query needs to be a bit dynamic in the code. The base LINQ I have written is rather simple

dim cust = from c in ctx.Customer
where c.Name = InputFromScreen
Select c.CustomerId, c.Name, c.JoinDate, C.State

Now that I have a base LINQ query, I can use lambda expressions to further reduce the queryset, depending on the screen input (append ANDs to the where).

Example: If the user entered in a value for the join date field:
cust = cust.Where(Function(c) c.JoinDate = DateFromScreen)

However I cannot figure out how to add the Where/Group for the state since the State is a navigation, not a table and I only want one row per customers, even if the customer has multiple states

The SQL for this would be rather simple (and this is not optimal, but appending the ANDs for each item on the screen is the simplest way to example)
select c.customerid, c.name
from customer c
where c.name = 'input' and c.JoinDate = 'input' and
c.customerid in (select customerid from state where state = 'IN')

I am thinking this is rather simple.

  • 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-30T11:02:04+00:00Added an answer on May 30, 2026 at 11:02 am

    The Linq to Entities equivalent to your SQL query would be:

    var customers = from c in ctx.Customer
                    where c.States.Any(s=> s.State == "IN")
                    select new { c.CustomerId, c.Name };
    

    This assumes you have a navigation property States on your Customer entity.

    (Above is C# syntax, I’m sure VB is somewhat similar)

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

Sidebar

Related Questions

I'm a bit new to SQL and have trouble constructing a select statement. I
I have a list of Fees (linq to sql entity- if relevant) - Upper
I am a bit new to LINQ, here is my problem. I have a
I'm new to infragistics. I have a database and a datalayer with entity framework
I have started using Linq to SQL in a (bit DDD like) system which
I have been using linq in combination with entity framework for a few months
Still a bit new to Linq. This is driving me nuts. I want to
I am a bit new to reusable plugins for jquery. I have ran across
I am a bit new to the Devel::Cover module, but have found it very
Learning a bit about Linq. I have the following code: (Please excuse the pathetic

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.