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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:39:01+00:00 2026-05-21T23:39:01+00:00

I want to use query over to give me back an object public class

  • 0

I want to use query over to give me back an object

 public class TaskMap : ClassMap<Task>
    {
        public TaskMap()
        {
            Table("Tasks");
            Id(x => x.TaskId);
            Map(x => x.TaskName).NvarcharWithMaxSize().Not.Nullable();
            Map(x => x.Description).NvarcharWithMaxSize();
            Map(x => x.DueDate).Not.Nullable();
            HasMany(x => x.PersonalTaskReminders).Inverse();
            HasMany(x => x.TaskReminders).Inverse();
            References(x => x.Course).Not.Nullable();
            HasMany(x => x.CompletedTasks);

        }
    }



[Serializable()]
public class Task
{
    public virtual int TaskId { get; private set; }
    public virtual string TaskName { get;  set; }
    public virtual string Description { get; set; }
    public virtual DateTime DueDate { get; set; }
    public virtual IList<PersonalTaskReminder> PersonalTaskReminders { get; set; }
    public virtual IList<TaskReminder> TaskReminders { get; set; }
    public virtual IList<CompletedTask> CompletedTasks { get; set; }
    public virtual Course Course { get; set; }

    public Task()
    {
        PersonalTaskReminders = new List<PersonalTaskReminder>();
        TaskReminders = new List<TaskReminder>();
        CompletedTasks = new List<CompletedTask>();
    }

}
     public class PlannerTask
{
    public int TaskId { get; set; }
    public string TaskName { get; set; }
    public string Description { get; set; }
    public DateTime DueDate { get; set; }
    public List<PersonalTaskReminder> PersonalTaskReminders { get; set; }
    public List<TaskReminder> TaskReminders { get; set; }
    public Course Course { get; set; }
    public bool IsCompleted { get; set; }


}

Try 1

Task tAlias = null;
        PlannerTask plannerTask = null;
        List<PlannerTask> result = session.QueryOver<Task>(() => tAlias)
            .Select(x => x.Course).TransformUsing(Transformers.AliasToBean<PlannerTask>())               
            .List<PlannerTask>().ToList();

result: 188 records with all null for course object.

Try 2

Task tAlias = null;
            PlannerTask plannerTask = null;
            List<PlannerTask> result = session.QueryOver<Task>(() => tAlias)
                         .Select(Projections.Property(() => tAlias.TaskId).WithAlias(() => plannerTask.TaskId),
                         Projections.Property(() => tAlias.TaskName).WithAlias(() => plannerTask.TaskName),
                         Projections.Property(() => tAlias.DueDate).WithAlias(() => plannerTask.DueDate),
                         Projections.Property(() => tAlias.Description).WithAlias(() => plannerTask.Description),
                         Projections.Property(() => tAlias.PersonalTaskReminders).WithAlias(() => plannerTask.PersonalTaskReminders),
                         Projections.Property(() => tAlias.TaskReminders).WithAlias(() => plannerTask.PersonalTaskReminders),
                         Projections.Property(() => tAlias.Course).WithAlias(() => plannerTask.Course))
                .TransformUsing(Transformers.AliasToBean<PlannerTask>())               
                .List<PlannerTask>().ToList();

Result: 188 courses with all properties having pretty much the same error

'((new System.Collections.Generic.Mscorlib_CollectionDebugView<Domain.PlannerTask>(result)).Items[0].Course).CoursePermissions' threw an exception of type 'NHibernate.ObjectNotFoundException'

Try 3

 Task tAlias = null;
        PlannerTask plannerTask = null;
        List<PlannerTask> result = session.QueryOver<Task>(() => tAlias)
             .Select(Projections.Property(() => tAlias.TaskId).WithAlias(() => plannerTask.TaskId),
             Projections.Property(() => tAlias.TaskName).WithAlias(() => plannerTask.TaskName),
             Projections.Property(() => tAlias.DueDate).WithAlias(() => plannerTask.DueDate),
             Projections.Property(() => tAlias.Description).WithAlias(() => plannerTask.Description),
             Projections.ProjectionList().Add(Projections.Property(()=> tAlias.PersonalTaskReminders).WithAlias(() => plannerTask.PersonalTaskReminders)),
             Projections.ProjectionList().Add(Projections.Property(()=> tAlias.TaskReminders).WithAlias(() => plannerTask.PersonalTaskReminders)),
             Projections.Property(() => tAlias.Course).WithAlias(() => plannerTask.Course))
            .TransformUsing(Transformers.AliasToBean<PlannerTask>())               
            .List<PlannerTask>().ToList();


SELECT this_.TaskId      as y0_,
       this_.TaskName    as y1_,
       this_.DueDate     as y2_,
       this_.Description as y3_,
       this_.TaskId      as y4_,
       this_.TaskId      as y4_,
       this_.CourseId    as y4_
FROM   Tasks this_

Result:

CoursePermissions = '((Castle.Proxies.CourseProxy)((new System.Collections.Generic.Mscorlib_CollectionDebugView<PlannerTask>(result)).Items[0].Course)).CoursePermissions' threw an exception of type 'NHibernate.ObjectNotFoundException'

try 4

Try 4

 Task tAlias = null;
        PlannerTask plannerTask = null;
        List<PlannerTask> result = session.QueryOver<Task>(() => tAlias)
             .Select(Projections.Property(() => tAlias.TaskId).WithAlias(() => plannerTask.TaskId),
             Projections.Property(() => tAlias.TaskName).WithAlias(() => plannerTask.TaskName),
             Projections.Property(() => tAlias.DueDate).WithAlias(() => plannerTask.DueDate),
             Projections.Property(() => tAlias.Description).WithAlias(() => plannerTask.Description),
             Projections.Property(() => tAlias.Course).WithAlias(() => plannerTask.Course))
            .TransformUsing(Transformers.AliasToBean<PlannerTask>())               
            .List<PlannerTask>().ToList();


SELECT this_.TaskId      as y0_,
       this_.TaskName    as y1_,
       this_.DueDate     as y2_,
       this_.Description as y3_,
       this_.CourseId    as y4_
FROM   Tasks this_

Works. I can access everything in the course object.

It seems to have a problem with

tAlias.PersonalTaskReminders and tAlias.TaskReminders. If I remove these Course will render fine.

I don’t understand why.

  • 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-21T23:39:02+00:00Added an answer on May 21, 2026 at 11:39 pm

    I think the problem is you are attempting to project Course proxy objects. Projections are for flat data transfer objects. You can declare the Course properties you need for this view.

    public class PlannerTask
    {
        public int TaskId { get; set; }
        public string TaskName { get; set; }
        public string Description { get; set; }
        public DateTime DueDate { get; set; }
        //flatten Course object
        public int CourseId { get; set; }
        public int CourseName { get; set; }
        public bool IsCompleted { get; set; }
    }
    

    The select list can be simplified a little…

    PlannerTask plannerTask = null;
    Course courseAlias = null;
    
    List<PlannerTask> result = session.QueryOver<Task>()
        .JoinAlias(x => x.Course, () => courseAlias)
        .SelectList(list => list
            .Select(x => x.TaskId).WithAlias(() => plannerTask.TaskId)
            .Select(x => x.TaskName).WithAlias(() => plannerTask.TaskName)
            .Select(x => x.DueDate).WithAlias(() => plannerTask.DueDate)
            .Select(x => x.Description).WithAlias(() => plannerTask.Description)
            .Select(x => x.Course.Id).WithAlias(() => plannerTask.CourseId))
            .Select(x => courseAlias.Name).WithAlias(() => plannerTask.CourseName))
        .TransformUsing(Transformers.AliasToBean<PlannerTask>())               
        .List<PlannerTask>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to use output caching to avoid hitting my db over and over
I want to use Second level Cache for my query with eager loading(query is
I have large data set, which I want to query. The query does not
Yesterday I have been testing one single query for over hours and hours, but
Sometimes if I want to quickly copy records from one table to another (that
I'm attempting to run a report which will give me daily plot sales over
Using CodeIgniter's Active Record class and MySQL, I have a table of posts with
I've got a query which I want to depend on certain parameters from an
I have a 'accdb' file and it has some queries. Now I want use
I want to iterate over records in the database and update them. However since

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.