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

  • Home
  • SEARCH
  • 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 8631663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:14:56+00:00 2026-06-12T09:14:56+00:00

I have two tables in SQL server for customers and their addresses. CREATE TABLE

  • 0

I have two tables in SQL server for customers and their addresses.

CREATE TABLE Customers
(
    ID              INT NOT NULL IDENTITY(1,1),
    LastName        VARCHAR(50) NOT NULL,
    FirstName       VARCHAR(50) NOT NULL,
    DateOfBirth     DATETIME2 NOT NULL,
    CONSTRAINT [PK_Customers] PRIMARY KEY CLUSTERED ([ID] ASC)
)
CREATE TABLE CustomerAddresses
(
    ID              INT NOT NULL IDENTITY(1,1),
    CustomerID      INT NOT NULL CONSTRAINT [FK_CustomerAddresses_Customers] FOREIGN KEY([CustomerID]) REFERENCES [dbo].[Customers] ([ID]),
    Street          VARCHAR(100) NOT NULL,
    City            VARCHAR(50) NOT NULL,
    Country         VARCHAR(50) NOT NULL,
    CONSTRAINT [PK_CustomerAddresses] PRIMARY KEY CLUSTERED ([ID] ASC)
)

I have generated a EFdatamodel and connecting to it using DataContext. I am trying to get all customers for a particular country. My code is as follows.

static List<Customer> GetByCountry(string country)  
        {  
            MyDbContext MyContext = new MyDbContext ();  
            return MyContext.Customers.Where(x => x.CustomerAddresses.Where( y => y.Country == country)).ToList();  
        }  

But I am getting following compilation errors.

Cannot implicitly convert type
‘System.Collections.Generic.IEnumerable’ to
‘bool’ Cannot convert lambda expression to delegate type
‘System.Func’ because some of the return
types in the block are not implicitly convertible to the delegate
return type

What am I doing wrong here?

  • 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-12T09:14:57+00:00Added an answer on June 12, 2026 at 9:14 am

    Your code must be

    return MyContext.Customers.Where(x => x.CustomerAddresses.Any( y => y.Country == country)).ToList();
    

    Because you want to return all Customers that have any address with the specified country. Where() expects a function that returns whether the condition is true, and returns an enumeration of all elements which hold this condition true. In your outer Where() your supply an argument that is of type IEnumerable (which is the return value of your inner where), and that is wrong.

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

Sidebar

Related Questions

In SQL Server 2008 I have two tables. One table for users: id_user -
I'm using SQL Server 2008. I have a table Customers customer_number int field1 varchar
I have a SQL Server 2005 table which lists customers and their order lines
Very new SQL Server, am using SQL server 2008. I have two tables, Table
I have two tables in sql server 2008 R2. one table has records as
I have two tables in SQL Server: Customer and Address Customer Table : CustomerID
I have two tables in SQL Server tbl_posting_job_info tbl_jobseeker_applied_job In this two table job_posting_id
I have two tables in Sql Server, one containing IDs for files and the
We have two tables in a SQL Server 2005 database, A and B.There is
Good Afternoon All, I have two tables in my SQL Server 2005 DB, Main

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.