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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:49:19+00:00 2026-05-12T23:49:19+00:00

I have the following nhibernate mapping <class name=Customer> <id name=Id> <generator class=native/> </id> <property

  • 0

I have the following nhibernate mapping

<class name="Customer">
  <id name="Id">
    <generator class="native"/>
  </id>
  <property name="Name"/>
  <set name="Invoices" cascade="all" lazy="false">
    <key column="CustomerId"/>
    <one-to-many class="Invoice"/>
  </set>
</class>

<class name="Invoice">
  <id name="Id">
    <generator class="native"/>
  </id>
  <property name="Status"/>
</class>

With these data objects

public enum InvoiceStatus { Unpayed, Payed };

public class Customer
{
    virtual public int Id { get; private set; }
    virtual public string Name { get; set; }
    virtual public ISet<Invoice> Invoices { get; set; }
}

public class Invoice
{
    virtual public int Id { get; private set; }
    virtual public InvoiceStatus Status { get; set; }
}

When I run the following code

t = session.BeginTransaction();
session.SaveOrUpdate(new Customer
{
    Name = "Customer1",
    Invoices = new HashedSet<Invoice> { new Invoice { Status = InvoiceStatus.Payed } }
});
session.SaveOrUpdate(new Customer
{
Name = "Customer2",
    Invoices = new HashedSet<Invoice> { new Invoice { Status = InvoiceStatus.Unpayed } }
    });
session.SaveOrUpdate(new Customer
{
    Name = "Customer3",
    Invoices = new HashedSet<Invoice> {
        new Invoice {Status = InvoiceStatus.Payed},
        new Invoice {Status = InvoiceStatus.Unpayed}
    }
});
session.SaveOrUpdate(new Customer { Name = "Customer4" });
t.Commit();

Console.WriteLine("{0} customers have payed invoices", session.Linq<Customer>().Where(c => c.Invoices.Any(i => i.Status == InvoiceStatus.Payed)).ToList().Count);
Console.WriteLine("{0} customers have unpayed invoices", session.Linq<Customer>().Where(c => c.Invoices.Any(i => i.Status == InvoiceStatus.Unpayed)).ToList().Count);
Console.WriteLine("Attempt 1: {0} customers have no invoices", session.Linq<Customer>().Where(c => c.Invoices.IsEmpty).ToList().Count);
Console.WriteLine("Attempt 2: {0} customers have no invoices", session.Linq<Customer>().Where(c => c.Invoices.Count == 0).ToList().Count);
Console.WriteLine("Attempt 3: {0} customers have no invoices", session.Linq<Customer>().Where(c => c.Invoices.Count() == 0).ToList().Count);

I get

2 customers have payed invoices
2 customers have unpayed invoices
Attempt 1: 4 customers have no invoices
Attempt 2: 3 customers have no invoices
Attempt 3: 3 customers have no invoices

The last three results are not what I expected, can you explain why?
And how would I get the right results?

  • 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-12T23:49:19+00:00Added an answer on May 12, 2026 at 11:49 pm

    To answer my own question. It works when I use !c.Invoices.Any() in the Where clause

    Console.WriteLine("Attempt 4: {0} customers have no invoices", session.Linq<Customer>().Where(c => !c.Invoices.Any()).ToList().Count);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following mapping: <hibernate-mapping package=server.modules.stats.data> <class name=User table=user> <id name=id> <generator class=native></generator>
Lets say I have the following mapping: <hibernate-mapping package=mypackage> <class name=User table=user> <id name=id
I have the following setup in app.config: <hibernate-configuration xmlns=urn:nhibernate-configuration-2.2 > <session-factory name=Nh.Data> <property name=connection.provider>
I have the following Nhibernate LINQ query: var query = from c in session.Query<Customer>()
I have the following mapping file: <?xml version=1.0 encoding=utf-8 ?> <hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 assembly=Project1.Accounts namespace=Project1.Core.Domain>
I'm having trouble mapping the following in NHibernate: I have two tables (these are
If I have the following domain object: public class Customer { public virtual Guid
I have the following NHibernate HBM that works as expected, but it makes my
I'm new to NHibernate... I have been following this NHibernate Tutorial from Gabriel Schenker
I have the following configuration file for NHibernate : <?xml version=1.0 encoding=utf-8 ?> <hibernate-configuration

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.