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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:09:39+00:00 2026-05-26T08:09:39+00:00

I need some help to write some queries. For this sql query (select *

  • 0

I need some help to write some queries.
For this sql query

(select * from NewsFeed where ID=10)

nHibernate query is

var set = sesssion.Query<NewsFeed>().Where(c => c.ID == 10).ToList();

These are queries I typically used. Now I want to write some complex query like this.

Does anyone know to write a query using Nhibernate Query for this sql query

select *
from  newsfeed
where AccountProfileID in 
       (select follow.FollowerID
       from follow
       where follow.AccountProfileID='1')

I am using .net C# and Mysql

please help!!

  • 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-26T08:09:40+00:00Added an answer on May 26, 2026 at 8:09 am

    NHibernate is an Object/Relational Mapper, so to properly ask a “how do I write this query” question, you need to provide enough information so that potential answerers can understand what these three things look like:

    • NHibernate entity classes (this is the Object part)
    • Database tables (this is the Relational part)
    • Mappings, whether they be HBM.XML, FluentNH, etc.

    Let’s assume your entities look something like this:

    public class AccountProfile
    {
        public virtual int Id { get; set; }
        public virtual string Name { get; set; }
        public virtual IList<NewsFeed> NewsFeeds { get; set; }
    
        /// <summary>
        /// People following me.
        /// </summary>
        public virtual IList<AccountProfile> Followers { get; set; }
    
        /// <summary>
        /// People I am following.
        /// </summary>
        public virtual IList<AccountProfile> Following { get; set; }
    }
    
    public class NewsFeed
    {
        public virtual int Id { get; set; }
        public virtual AccountProfile AccountProfile { get; set; }
        public virtual string Name { get; set; }
    }
    

    … where Followers and Following are opposite sides of a many-to-many relationship. This should be enough info for most people to be able to fill in the blanks and intuitively understand what the tables and mappings look like.

    Now that we have that foundation, let’s work on the query. Your query will be a bit easier to deal with if we rewrite it to use a join instead of a subquery:

    select newsfeed.*
    from
        newsfeed
        inner join follow
            on newsfeed.AccountProfileID = follow.FollowerID
    where follow.AccountProfileID='1'
    

    This query should be exactly equivalent in behavior to the original query, more in-line with a relational database mindset, and perhaps a bit more efficient.

    The equivalent NHibernate QueryOver (my preferred query API) query would look like this:

    AccountProfile accountProfileAlias = null;
    AccountProfile followingAlias = null;
    
    var feeds = session.QueryOver<NewsFeed>()
        .JoinAlias(x => x.AccountProfile, () => accountProfileAlias)
        .JoinAlias(() => accountProfileAlias.Following, () => followingAlias)
        .Where(() => followingAlias.Id == 1)
        .List();
    

    Let’s translate this query into English: “Select the list of newsfeeds belonging to all the people who are following account #1.” However, I have a feeling you meant “Select the list of newsfeeds belonging to all the accounts followed by account #1”, which seems to me to be a bit more useful. In QueryOver, that looks like this (replace Following with Followers).

    AccountProfile accountProfileAlias = null;
    AccountProfile followerAlias = null;
    
    var feeds = session.QueryOver<NewsFeed>()
        .JoinAlias(x => x.AccountProfile, () => accountProfileAlias)
        .JoinAlias(() => accountProfileAlias.Followers, () => followerAlias)
        .Where(() => followerAlias.Id == 1)
        .List();
    

    If someone else wants to take a stab at this using NHibernate’s LINQ provider, a.k.a. session.Query, feel free, but I personally don’t have as much experience with that API.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write Linq-To-SQL queries in LinqPad to help migrate users from old
I need some help calculating Pi. I am trying to write a python program
I need some help understanding this bit of code pre { white-space: pre; white-space:
Need some help to solve this. I have a gridview and inside the gridview
Need some help with this problem in implementing with XSLT, I had already implemented
Need some help gathering thoughts on this issue. Our team is moving ahead with
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
I need some help from the shell-script gurus out there. I have a .txt
I am new to Python and need some help. i need to write a
I need some help reading data from a text file into my ArrayList .

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.