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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:57:55+00:00 2026-05-17T23:57:55+00:00

Suppose I have classes Foo and Bar as follow: public class Foo { public

  • 0

Suppose I have classes Foo and Bar as follow:

public class Foo
{
public string F1 {set; get;}
public string F2 {set; get;}

public Bar ContainerBar {set; get;}
}

public class Bar
{
public string B1 {set; get;}
public string B2 {set; get;}

public List<Foo> Foos {set; get;}
}

Following linq query has errors saying that foo does not contain a property named F1.

var query = from foo in session.Linq<Foo>()
                 select foo.ContainerBar;

query = query.Where(foo => foo.F1 == "abcdef");

I know foo in second statement is really a Bar because query selects ContainerBar.

The question is know how can I add a dynamic where clause to query without changing origianl query? Final goal is to have sub-queries with linq-to-nhibernate.

  • 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-17T23:57:56+00:00Added an answer on May 17, 2026 at 11:57 pm
    var query = from foo in session.Linq<Foo>()
                     select foo.ContainerBar;
    
    query = query.Where(foo => foo.F1 == "abcdef");
    

    Your “query” object is now an IQueryAble of ContainerBar’s
    So when you do the Where( foo => foo.F1 == “abcdef” ), it’s done on IQueryable, so no F1 property.

    You should do:

    var bars = from foo in session.Linq<Foo>()
                where foo.F1 == "abcdef"
                select foo.ContainerBar;
    

    Or:

    var q = session.Linq<Foo>();
    
    // if some condition
    q = q.Where( foo => foo.F1 == "abcdef" );
    
    var bars = q.Select( foo => foo.ContainerBar );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have a collection of Foo classes: class Foo { public string Bar;
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose, I have following classes: public class DisposableObj : IDisposable { public ChildObj CreateObj();
Suppose I have two classes defined the following way: public class A { public
Suppose I have these abstract classes Foo and Bar : class Foo; class Bar;
Suppose we have two classes: class Base { private: int x; public: void f();
Suppose you have 2 classes like so: public class ClassA { public int X
Suppose I have the following class hierarchy: class A { int foo; virtual ~A()
Suppose I have two classes with the same interface: interface ISomeInterface { int foo{get;
Suppose i have a classes like this @Entity public class Customer implements Serializable {

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.