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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:49:41+00:00 2026-05-28T16:49:41+00:00

We have a complex business model and is using NHibernate to create and maintain

  • 0

We have a complex business model and is using NHibernate to create and maintain the database. This results in poor performance from time to time when a fairly straight forward query results in a large object graph.

Usually we are able to rewrite the query and gain a good performance boost while at the same time getting to know the business model better. However now we have stumbled over a case where we are unable to get a better result that what we currently have which, frankly, is really really poor.

We have the following classes with associated mappings. The classes have been stripped down to minimum just let me know if you need more information.

public class GraphPoint
{
   public DateTime datum;
   public IDictionary<Avtal, Value> values;
   public Calculation calculation;
   public bool isCalculated;
   public Int64 graphPointId;

   ...
}

public class Value
{
   public int numbers;
   public int points;
}

public class Avtal
{
   public string name;
   public Int64 avtalId

   ...
}

<class name="GraphPoint" lazy="false">
   <id name="GraphPointId" column="GraphPointId" type="Int64">
     <generator class="Business.Data.IncrementGenerator, Business"/>
   </id>

   <property name="Datum" not-null="true" unique-key="UIX1_GraphPoint" />
   <map name="Values" table="GraphPointValue" cascade="all-delete-orphan">
     <key column="GraphPointId" foreign-key="FK_GraphPoint_GraphPointValue" />
     <map-key-many-to-many class="Avtal" column="AvtalId" 
                           foreign-key="FK_GraphPoint_GraphPointValue_Avtal"  />
     <composite-element class="GraphPoint+Value">
       <property name="Numbers" not-null="true" />
       <property name="Points" not-null="true" precision="26" scale="15" />
     </composite-element>
   </map>
   <property name="IsCalculated" not-null="true" />
   <many-to-one name="Calculation" column="CalculationId" 
                foreign-key="FK_Calculation_GraphPoint" />
</class>

So in this scenario we the following criterias:
* Return all GraphPointValues between two dates
* Aggregate these based on the Avtal object

We currently have been trying with this:

from punkt in (from punkt in Session.Query<GraphPoint>()
               where punkt.IsCalculated && 
                     punkt.Datum >= lowDate && 
                     punkt.Datum <= highDate
               select punkt).ToArray()
let values = from value in punkt.Values
             where forAvtal.Contains(value.Key.AvtalId)
             select value.Value
select new GraphPointValuePresentationObject
{
   Datum = punkt.Datum,
   Numbers = värden.Sum(v => v.Antal),
   Points = värden.Sum(v => v.Poäng),
   IsCalculated = punkt.IsCalculated
}

forAvtal is a list containing id’s for these objects that shoudl be met.

When we run this we get one sql-statement against the database which fetches all the GraphPoints that lay between the dates and then we get one sql-statment for each and everyone of the points that the first sql-statement returns.

I want to rewrite this so that we only need a couple of sql-statements and not several hundreds as it is today. Can anyone give me a pointer in the right direction, I’ve tried Critierias and DetachedQueries but can’t get it to work as I want to.

  • 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-28T16:49:42+00:00Added an answer on May 28, 2026 at 4:49 pm

    inserting .Fetch(x => x.Values) befor .ToArray() should do the trick. It will generate a join to fetch all related values along with the Graphpoints

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

Sidebar

Related Questions

We currently have a quite complex business application that contains a huge lot of
I am using WCF and REST, and I have complex types, which are working
I have a fairly complex business application written in ASP.NET that is deployed on
I have a complex, 3NF database being provided to me for a particular project.
I have a method in a repository with a very complex business logic. I
I have complex GUI application written in Python and wxPython. I want it to
I have a complex query with group by and order by clause and I
I have a complex .NET Remoting server app that provides a couple of services.
I have a complex command that I'd like to make a shell/bash script of.
I have some complex stored procedures that may return many thousands of rows, and

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.