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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:13:11+00:00 2026-05-12T13:13:11+00:00

I have a linq query that is passed into NHibernate which Linq2NHibernate will parse

  • 0

I have a linq query that is passed into NHibernate which Linq2NHibernate will parse and return me populated entities.

string firstName = "Ryan";
Store store = _repository.Query<Store>().Where(x => x.Employees.Select(y => y.FirstName).Contains(firstName)).FirstOrDefault();

The troublesome part is x => x.Employees.Select(y => y.FirstName).Contains(firstName)

What this should be doing is selecting Stores that have Employees with the name Ryan.

I receive an error on the line above stating “Unhandled Expression Type: 1004“

It appears to me that it is a limitation of Linq2NHibernate and the .Select().Contains() just can’t be parsed.

Any ideas? Has anyone else every received this error? What can I do to fix it or work around it?

[EDIT]

Here is what I ended up using instead.

string firstName = "Ryan"
Store store = _repository.Query<Store>().Where(x => x.Employees.Any(y => y.FirstName == firstName)).FirstOrDefault();

The Linq query being x => x.Employees.Any(y => y.FirstName == firstName)

  • 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-12T13:13:11+00:00Added an answer on May 12, 2026 at 1:13 pm

    I don’t use LINQ to NHibernate, but that’s not how I’d write that query anywhere else. Try:

    string firstName = "Ryan";
    Store store = _repository.Query<Store>()
                             .Where(s => s.Employees.Any(
                                    e => e.FirstName.Equals(
                                         firstName,  StringComparison.WhateverTypeYouNeed))
                   ).FirstOrDefault();
    

    If L2NH doesn’t like string.Equals(), try ==

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

Sidebar

Related Questions

I have a List of X items. I want to have LINQ query that
I have a LINQ query that uses lambda syntax: var query = books .Where(book
I have a simple LINQ query that is going against a collection. Dim oList
I am learning LINQ, and I am not sure how to write a query
Possible Duplicate: What is the LINQ way to implode/join a string array? Say I
I'm reading manning book about LINQ, and there is an example: static class QueryReuse
Guess people need some experience with Linq-to-xml and knowledge of the build of a
I have a simple view defined MSSQL 2008. The view is defined as follows:
First let me start by explaining my use case: Say there is a database
I am reading this asp.net article on building your first asp.net mvc 2 website

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.