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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:41:17+00:00 2026-05-13T20:41:17+00:00

Short Version This query works in the database but fails with Linq To NHibernate.

  • 0

Short Version
This query works in the database but fails with Linq To NHibernate. Why?

var items = (from g in db.Find<DataGroupInfo>() 
              where (from d in g.data where d.Id == dataID select d).Count() > 0  
              select g).ToList();

Detailed Long Version

I have two objects mapped by NHibernate Automapper with a ManyToMany relationship.

return Fluently.Configure()
     //a few other settings here...
     //relevant settings below
               .Override<DataGroupInfo>(map =>
               {
                   map.HasManyToMany(d => d.data);
               }
               .Conventions.Add(DefaultCascade.All())
               .Conventions.Add(DefaultLazy.Never())


public class DataInfo
{
    public virtual int Id { get; private set; }
    public virtual DateTime created { get; set; }
    public virtual string label { get; set; }
    public virtual string description { get; set; }
}

public  class DataGroupInfo
{
    public virtual Int32 Id { get; set; }

    public virtual DateTime created { get; set; }
    public virtual string label { get; set; }
    public virtual string description { get; set; }

    public virtual IList<DataInfo> data { get; set; }
}

I want to grab all the DataGroups that contain a certain DataInfo.

This query works in SQLite admin so I think my database is properly setup:

select * from DataGroupInfo
INNER JOIN DataInfoToDataGroupInfo ON
DataGroupInfo.Id ==  DataInfoToDataGroupInfo.DataGroupInfo_id
where
DataInfoToDataGroupInfo.DataInfo_id == 3

I’m a repository that exposes Linq in these two ways

public IQueryable<T> Find<T>()
{
    return session.Linq<T>();
}

public IQueryable<T> Find<T>(Expression<Func<T, bool>> predicate)
{
    return Find<T>().Where(predicate);
}

I use the repositories like this

  static public List<DataGroupInfo> GetAllWithData(Int32 dataID)
    {
        using (var db = new DBRepository())
        {
            //var items = (from g in db.Find<DataGroupInfo>() 
            //                where (from d in g.data where d.Id == dataID select d).Count() > 0  
            //             select g).ToList();

            var items = db.Find<DataGroupInfo>(dg => dg.data.Where(d => d.Id == dataID).Count() > 0 ).ToList();

            return items;
        }
    }

When the Linq tries to execute above I get the following error under either method:

NHibernate.QueryException was
unhandled by user code
Message=”could not resolve property:
data.Id of:
MapLarge.Public.Data.DataGroupInfo”
Source=”NHibernate” StackTrace:
at NHibernate.Persister.Entity.AbstractPropertyMapping.GetColumns(String
propertyName)

What am I doing wrong?

—-Update—–

This work around gives the expected result, but its a brute force approach pulling every datagroup into memory and then filtering objects using c# rather than the database.. but at least it narrows down my problem to a NHibernate specific issue.

        var step1 = db.Find<DataGroupInfo>().ToList();
        var items = step1.Where(dg => dg.data.Where(d => d.Id == dataID).Count() > 0).ToList();

I’d still really love an answer if anyone is out there 🙂

  • 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-13T20:41:18+00:00Added an answer on May 13, 2026 at 8:41 pm

    LINQ-to-NHibernate currently does not support subqueries or joins: http://ayende.com/Blog/archive/2009/07/26/nhibernate-linq-1.0-released.aspx

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

Sidebar

Related Questions

so this is my problems short version: This works: $query = mysql_query(SELECT * FROM
So the short version of this is: Can I traverse only the elements within
Short version : echo testing | vim - | grep good This doesn't work
The short version of the question - why can't I do this? I'm restricted
So the wonderful low down on this doozie of a problem: short version: We
This is basically a rails 3 version of this question . Short of parsing
Short version of Problem Autocomplete works when the input string matches the result string,
To short version of this question is that I want to accomplish something along
Short version: How can I have my form's button label text differ from the
I'm using the current Linq provider for NHibernate (version 2.1). I have two entities:

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.