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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:17:48+00:00 2026-05-28T02:17:48+00:00

I have a set of subclassed domain objects that I fetch with Linq and

  • 0

I have a set of subclassed domain objects that I fetch with Linq and NHibernate. Here’s an example of what I have:

public abstract class Car {
    public abstract bool Runs();
}

public class Junker : Car { 
    public override bool Runs() {
        return false;
    }
}

public class NewCar : Car { 
    public override bool Runs() {
        return true;
    }
}

What I need to do is to fetch only the cars that Run(). So, I want to do this:

var goodCars = _session.Query<Car>().Where(car => car.Runs());

… but, that doesn’t work because Runs() isn’t a supported query source. Here’s the error I get:

Cannot parse expression 'car' as it has an unsupported type. Only query sources (that is, expressions that implement IEnumerable) and query operators can be parsed.

I’ve tried separating the query into two steps: 1) get all cars, 2) filter by Runs() … but I can’t do this because it breaks Lazy Loading (my domain model is a bit more complex that my car example). Besides, I only want to fetch the items from the database that actually fit my query.

Is there a way to do what I’m trying to do?

  • 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-28T02:17:49+00:00Added an answer on May 28, 2026 at 2:17 am

    You cannot do this. The thing you’re trying to do is impossible to translate into a SQL query and since that is all NHibernate is doing ultimately…no.

    To get all with one query is going to require you dropping down to the db level and using some non-domain knowledge. I recommend hiding this behind a service interface.

    public interface RunningCars {
    IEnumerable All();
    }

    and implementing it using maybe a custom sql query or a stored procedure.

    How does doing it in 2 steps break lazy loading? Perhaps you need to specify that you want to pre-fetch those asociations during the initial query.

    Also in this specific example, couldn’t you just fetch all instances of NewCar?

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

Sidebar

Related Questions

I have set an onPreferenceClickListener on my subclass of DialogPreference like so: public class
I have this: namespace Demo.Framework.Domain { public class UserEntity { public virtual Guid UserId
I have created a class, Metrics that is designed to be subclassed to customize
In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes
I have a subclass of UIScrollView that I have set as the view of
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have an OrderForm domain class, which has property subclasses, something like: interface IOrderForm
I'm trying to write a Django-subclassed ModelChoiceField class that knows how to load itself,
Currenly in my cellForRowAtIndexPath function i have subclassed two UILabels that holds the values
I have a QTreeView to which I set a subclassed DomModel:QAbstractItemModel. Each item is

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.