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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:39:34+00:00 2026-05-27T02:39:34+00:00

I have a Activity entity, this entity can have several Task. Here the code

  • 0

I have a “Activity” entity, this entity can have several “Task”.

Here the code for the entities :

public class Activity : Entity<int>
{
    public virtual int Id { get; set; }
    public virtual string Code { get; set; }
    public virtual string Name { get; set; }
    public virtual Iesi.Collections.Generic.ISet<Task> Tasks { get; set; }

    public Activity()
    {
        Tasks = new Iesi.Collections.Generic.HashedSet<Task>(); 
    }
}

public class Task
{
    public virtual int Id { get; set; }
    public virtual string Code { get; set; }
    public virtual string Name { get; set; }
    public virtual Activity Activity { get; set; } 
}

The mapping :

public ActivityMap()
{
    Id(x => x.Id).GeneratedBy.Native();
    Map(x => x.Code);
    Map(x => x.Name);

    HasMany(x => x.Tasks)
        .KeyColumns.Add("Activity")
        .AsSet()
        .Inverse()
        .Cascade.AllDeleteOrphan();
}

public TaskMap()
{
    Id(x => x.Id).GeneratedBy.Native();
    Map(x => x.Code);
    Map(x => x.Name);
}

The test :

activity = new Activity
{
    Code = "...",
    Name = "..."
};

Task task = new Task
{
    Code = "...",
    Name ="...",
    Activity = activity
};
session.Save(activity);

I see whit NHProf 2 insert.
After the commit, I do a GetById of the entity “Activity” but the “Tasks” property is empty. In the database, the field “Activity” (entity “Task”) is null.

  • 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-27T02:39:35+00:00Added an answer on May 27, 2026 at 2:39 am
    activity = new Activity
    {
        Code = "...",
        Name = "..."
    };
    
    Task task = new Task
    {
        Code = "...",
        Name ="...",
        Activity = activity
    };
    activity.Tasks.Add(task);
    session.Save(activity);
    

    You have to keep the relation between two objects in both sides.

    P.S. maybe you should change the cascade to be .Cascade.All(); because when I tryed Delete orphan it just didn’t seem to work right.

    Update: as @Stefan Steinegger mentioned you didn’t Map the activity.

    public TaskMap()
    {
        Id(x => x.Id).GeneratedBy.Native();
        Map(x => x.Code);
        Map(x => x.Name);
        References( x => x.Activity); //Missing mapping 
    }
    

    But you still need to update the relation in both sides.

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

Sidebar

Related Questions

Let's say I have an entity that looks like this: public class Album() {
Going round in circles here i think. I have an activity called Locate; public
I have an activity that extends MapActivity, and inside onCreate() I have this code
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have the following problem: I have an Activity where a user can start
I have created a custom workflow activity in CRM that creates a task. The
I need some help with Hibernate Projections. I have a class called Activity with
Probably a common problem, but anyway: Let's say I have a simple entity Task
I have a Django model (schedule) with the class of entity, that is the
I have the fallowing NHibernate-Mapping: <class name=Activity table=Activity lazy=false > <cache usage=read-write/> <id name=Id

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.