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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:17:17+00:00 2026-05-16T01:17:17+00:00

I have 3 methods that are almost exactly identical: protected DetachedCriteria GetAvailableFundIdsPerDataUniverse() { return

  • 0

I have 3 methods that are almost exactly identical:

protected DetachedCriteria GetAvailableFundIdsPerDataUniverse()
{
    return GetAvailableIdsPerDataUniverse()
        .SetProjection(LambdaProjection.Property<Fund>(f => f.Id));
}

protected DetachedCriteria GetAvailableCompanyIdsPerDataUniverse()
{
    return GetAvailableIdsPerDataUniverse()
        .SetProjection(LambdaProjection.Property<Fund>(f => f.Company.Id));
}

protected DetachedCriteria GetAvailableCategoryIdsPerDataUniverse()
{
    return GetAvailableIdsPerDataUniverse()
        .SetProjection(LambdaProjection.Property<Fund>(f => f.Category.Id));
}

where GetAvailableIdsPerDataUniverse() is defined as:

protected DetachedCriteria GetAvailableIdsPerDataUniverse()
{
    return DetachedCriteria.For<Fund>()
        .SetFetchMode<Fund>(f => f.ShareClasses, FetchMode.Join)
        .CreateCriteria<Fund>(f => f.ShareClasses)
        .Add(LambdaSubquery.Property<ShareClass>(x => x.Id).In(GetAvailableShareClassIdsPerDataUniverse()))
        .Add<ShareClass>(f => f.ExcludeFromFT == false);
}

For each method, the only difference is the expression that’s used to select the data, i.e.

f => f.Id, f => f.Company.Id and f => f.Category.Id

Could somebody please tell me if it’s possible to pass that those differences into GetAvailableIdsPerDataUniverse() as a variable so I can have only 1 method instead of having 4?

  • 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-16T01:17:17+00:00Added an answer on May 16, 2026 at 1:17 am

    typing directly in browser, so may not contain errors

    protected DetachedCriteria GetAvailableIdsPerDataUniverse(Expression<Fund, int> e)
    {
        return DetachedCriteria.For<Fund>()
            .SetFetchMode<Fund>(f => f.ShareClasses, FetchMode.Join)
            .CreateCriteria<Fund>(f => f.ShareClasses)
            .Add(LambdaSubquery.Property<ShareClass>(x => x.Id).In(GetAvailableShareClassIdsPerDataUniverse()))
            .Add<ShareClass>(f => f.ExcludeFromFT == false).
            .SetProjection(LambdaProjection.Property<Fund>(e));
    }
    
    GetAvailableIdsPerDataUniverse(e => e.Category.Id)
    //...
    

    Edit
    I’ve checked documentation of NHibernate.LambdaExtensions, type of LambdaProjection.Property is

    public static PropertyProjection Property<T>(Expression<Func<T, object>> expression)
    

    So parameter type should be

    System.Linq.Expressions.Expression<Func<Fund, object>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two methods that are almost identical. The only dffernece is the where
I have several methods that have a return type IEnumerable<T> . These methods are
I’m after some C# code that will have the following methods that will return
I have the following two methods that get data from my DB and return
I have two methods that look almost the same, except for the aggregate function
In C# I have methods that use [WebMethod(EnableSession = true)] I consume them in
I have several methods that populate a SQLCommand objects parameter collection from an object
I have some methods that are used by several classes. My idea was to
I have two action methods that are conflicting. Basically, I want to be able
I have many js methods that uses global variables like: function DoSomething() { var

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.