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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:06:33+00:00 2026-05-21T20:06:33+00:00

I’m using NHibernate 2, and I’d like to be able to do the following:

  • 0

I’m using NHibernate 2, and I’d like to be able to do the following:

I have many DAO types. They are all subclasses of BaseDAO, but they are not related in the NHibernate mappings at all. (These subclasses dot not all have common properties.)

I want to write a method that will search all of my DAO types and return a List<BaseDAO> containing all matches.

The method signature should look something like:

public IList<BaseDAO> GlobalSearch(string searchTerm, int startIdx, int maxRows);

The query needs to check searchTerm against all string properties of the domain types. We are currently doing this for one type at a time using a method that builds a Disjunction to search on all properties for a given type.

private Disjunction BuildDisjunction(string searchTerm, Type type)

I’d like to combine all of the disjunctions for all of my domain types and create one query that will return a list of the BaseDAO.

Here is what I have so far:

public IList<DomainBase> GlobalSearch(string searchTerm, 
                                      int startIndex, int maxRows)
{
    ICriteria crit = GetCriteria<BaseDAO>();
    foreach (Type t in GetAllDomainTypes())
    {
        Disjunction disj = BuildDisjunction(searchTerm, t);
        // somehow use this disjunction
    }
    crit
        .AddOrder(Order.Asc("DispName"))
        .SetFirstResult(startIdx)
        .SetMaxResults(maxRows);
    return crit.List<BaseDAO>(); ;
}

Is this possible? How can I modify/complete the above method to achieve the functionality I need?

  • 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-21T20:06:34+00:00Added an answer on May 21, 2026 at 8:06 pm

    This method will only work with MSSQL Server.

    Ok I’ve written the following, I hope it’s what you’re after, it can be refactored but it will get you started.

    Given the following test classes:

    public class BaseClass
    {
        public virtual int Id { get; set; }   
    }
    
    public class TestClassOne : BaseClass
    {
        public virtual string Name { get; set; }
    }
    
    public class TestClassTwo : BaseClass
    {
        public virtual string Value { get; set; }
        public virtual string Hobby { get; set; }
    }
    
    public class TestClassThree : BaseClass
    {
        public virtual string Month { get; set; }
        public virtual int Day { get; set; }
    }
    
    public class TestClassFour : BaseClass
    {
        public virtual string Title { get; set; }
        public virtual string Content { get; set; }
    }
    

    Can query the all those classes by reflecting them, then reflecting the properties which are a type of string.

            var session = new SessionFactoryManager().CreateSessionFactory().OpenSession();
            var criteria = session.CreateMultiCriteria();
    
            //Find classes that inherit from BaseClass
            var classses = Assembly.GetExecutingAssembly().GetTypes().Where(x => x.BaseType == typeof(BaseClass));
            var searchValue = "Test";
    
            foreach (var classs in classses)
            {
                //Find all the properties that are typeof string
                var properties = classs.GetProperties()
                                       .Where(x => x.PropertyType == typeof(string));
    
                var query = DetachedCriteria.For(classs);
    
                foreach (var memberInfo in properties)
                {
                    query.Add(Restrictions.InsensitiveLike(memberInfo.Name, searchValue, MatchMode.Anywhere));
                }
    
                criteria.Add(query);
            }
    
            var results = criteria.List()
                                  .Cast<ArrayList>()
                                  .ToList()
                                  .SelectMany(x => x.ToArray())
                                  .Cast<BaseClass>()
                                  .ToList();
    
            foreach (var result in results)
            {
                Console.WriteLine(result.Id);
            }
    

    Will generate a single query batch like so:

    SELECT this_.Id   as Id1_0_,
           this_.Name as Name1_0_
    FROM   TestClassOne this_
    WHERE  lower(this_.Name) like '%test%' /* @p0 */
    
    
    SELECT this_.Id    as Id3_0_,
           this_.Value as Value3_0_,
           this_.Hobby as Hobby3_0_
    FROM   TestClassTwo this_
    WHERE  lower(this_.Value) like '%test%' /* @p1 */
           and lower(this_.Hobby) like '%test%' /* @p2 */
    
    
    SELECT this_.Id    as Id2_0_,
           this_.Month as Month2_0_,
           this_.Day   as Day2_0_
    FROM   TestClassThree this_
    WHERE  lower(this_.Month) like '%test%' /* @p3 */
    
    
    SELECT this_.Id      as Id0_0_,
           this_.Title   as Title0_0_,
           this_.Content as Content0_0_
    FROM   TestClassFour this_
    WHERE  lower(this_.Title) like '%test%' /* @p4 */
           and lower(this_.Content) like '%test%' /* @p5 */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have some data like this: 1 2 3 4 5 9 2 6
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a text area in my form which accepts all possible characters from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
In order to apply a triggered animation to all ToolTip s in my app,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.