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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:08:45+00:00 2026-05-23T18:08:45+00:00

In Fluent NHibernate, is it possible to add a parameter to a filter of

  • 0

In Fluent NHibernate, is it possible to add a parameter to a filter of type List<int> so that the filter condition generates a WHERE SomeColumn IN (@x, @y, @z) ?

My use case is to fetch an invoice and a subset of its lines, given the ID of the invoice and a list of invoice line numbers. I want to eager fetch the lines in the same roundtrip as the invoice. I assume it is done something like this, but I cannot find the correct type declaration for the parameter type:

Domain objects:

public class Invoice {
  public int Id {get;set;}
  public List<InvoiceLine> Lines {get;set;}
}

public class InvoiceLine {
  public int Id {get;set}
  public int LineNumber {get;set;}
}

Mappings:

public class InvoiceMap : ClassMap<Invoice> {
  public InvoiceMap() {
    Id(x => x.Id);
    HasMany(x => x.Lines).ApplyFilter<OnlyLinesWithNumbersFilter>();
  }
}

public class InvoiceLineMap : ClassMap<InvoiceLine> {
  public InvoiceLineMap() {
    Id(x => x.Id);
    Map(x => x.LineNumber);
  }
}

Filter definition:

public class OnlyLinesWithNumbersFilter : FilterDefinition
{
    public OnlyLinesWithNumbersFilter()
    {
        WithName("OnlyLinesWithNumbers");
        WithCondition("LineNumber IN (:LineNumbers)");
        AddParameter("LineNumbers",?? What to put here ??);
    }
}

Query:

var filterName = "OnlyLinesWithNumbers";
session.EnableFilter(filterName).SetParameterList("LineNumbers", new[] {1,2,3});

var query = session.QueryOver<Invoice>()
       .Where(i => i.Id == 42)
       .Fetch(i => i.Lines).Eager
       .TransformUsing(new DistinctRootEntityResultTransformer());

var result = query.SingleOrDefault();
session.DisableFilter(filterName);
  • 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-23T18:08:46+00:00Added an answer on May 23, 2026 at 6:08 pm

    Take-2

    InvoiceLine invoiceLineAlias = null;
    var list = session.QueryOver<Invoice>()
                      .Where(x => x.Id == 1)
                      .JoinQueryOver(x => x.Lines, () => invoiceLineAlias, JoinType.LeftOuterJoin)
                      .WhereRestrictionOn(() => invoiceLineAlias.LineNumber)
                      .IsIn(new List<int> { 1, 2, 3 })
                      .List();
    

    produced sql:

    SELECT
            this_.Id as Id2_1_,
            invoicelin1_.Invoice_id as Invoice3_3_,
            invoicelin1_.Id as Id3_,
            invoicelin1_.Id as Id3_0_,
            invoicelin1_.LineNumber as LineNumber3_0_
        FROM
            "Invoice" this_
        left outer join
            "InvoiceLine" invoicelin1_
                on this_.Id=invoicelin1_.Invoice_id
        WHERE
            this_.Id = @p0
            and invoicelin1_.LineNumber in (
                @p1, @p2, @p3
            );
        @p0 = 1 [Type: Int32 (0)], 
        @p1 = 1 [Type: Int32 (0)], 
        @p2 = 2 [Type: Int32 (0)], 
        @p3 = 3 [Type: Int32 (0)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use Fluent NHibernate's PersistenceSpecification to test NHibernate mappings done via
If using Fluent NHibernate, is it possible to automap most classes, but specify that
Is it possible to use something like this wrapper with fluent configuration? http://jeffreypalermo.com/blog/use-this-nhibernate-wrapper-to-keep-your-repository-classes-simple/ If
Is it possible to have a discriminator that works like this with NHibernate? If
Is there a way in Fluent NHibernate to specify that a foreign key should
It's possible to map a VIEW using Fluent NHibernate? If so, how?
NHibernate seems to support a special case of one to one mapping (That doesn't
Is it possible yet to do a one-to-one mapping with fluent nhibernate? I have
While developing with Fluent nHibernate, I notice that on relationships I can specify a
Is it possible to map an enum as a string using Fluent Nhibernate?

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.