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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:34:50+00:00 2026-06-05T15:34:50+00:00

I am very new to Nhibernate. I would like to develop an application in

  • 0

I am very new to Nhibernate. I would like to develop an application in asp.net by using NHibernate as mapping database tools.

I have following tables schemas:

CREATE TABLE [dbo].[tblTeam](
    [TeamID] [int] IDENTITY(1,1) NOT NULL,
    [TeamName] [varchar](100) NOT NULL
)


CREATE TABLE [dbo].[tblEmployee](
    [EmployeeID] [int] IDENTITY(1,1) NOT NULL,
    [EmployeeName] [varchar](100) NOT NULL
)

CREATE TABLE [dbo].[tblTeamEmployee](
    [TeamID] [int] NOT NULL,
    [EmployeeID] [int] NOT NULL
)

And here is Nhibernate mapping file that I have made:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="TelDir.Core.Domain.Team, TelDir.Core" table="tblTeam" lazy="false">
    <id name="ID" column="TeamID" unsaved-value="0">
      <generator class="identity" />
    </id>

    <property name="TeamName" column="TeamName" />

    <bag name="Employees" cascade="none" table="tblTeamEmployee" lazy="false" access="readonly">
      <key column="EmployeeID"/>
      <many-to-many class="TelDir.Core.Domain.Employee, TelDir.Core" column="TeamID"/>
    </bag>

  </class>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="TelDir.Core.Domain.Employee, TelDir.Core" table="tblEmployee" lazy="false">
    <id name="ID" column="EmployeeID" unsaved-value="0">
      <generator class="identity" />
    </id>

    <property name="EmployeeName" column="EmployeeName" />        

    <bag name="Teams" cascade="none" table="tblTeamEmployee" lazy="false" >
      <key column="EmployeeID"/>
      <many-to-many class="TelDir.Core.Domain.Team, TelDir.Core" column="EmployeeID"/>
    </bag>

  </class>
</hibernate-mapping>

And my POCO class is defined as below:

namespace TelDir.Core.Domain
{
    public class Team   {

        private string _TeamName = "";
        private IList<Employee> _employees = new List<Employee>();

        public Team() { }

        public  string TeamName {
            get { return _TeamName }
            set { _TeamName = value; }
        }


        public  IList<Employee> Employees
        {
            get { return new List<Employee>(_employees).AsReadOnly(); }
            protected set { _employees = value; }          
        }

        public  void AddEmployee(Employee em)
        {
            if (!_employees.Contains(em)){
                _employees.Add(em);
            }
        }

        public  void RemoveEmployee(Employee em)
        {
            if (_employees.Contains(em)){
                _employees.Remove(em);
            }
        }  
    }
}




namespace TelDir.Core.Domain
{
    public class Employee  {

        private string _EmployeeName = "";
        private IList<Team> _teams = new List<Team>();

        public Employee() { }

        public  string EmployeeName {
            get { return _EmployeeName}
            set { _EmployeeName = value; }
        }


        public  IList<Team> Teams
        {
            get { return new List<Team>(_teams).AsReadOnly(); }
            protected set { _teams = value; }          
        }

        public  void AddTeam(Team tm)
        {
            if (!_teams.Contains(tm)){
                _teams.Add(tm);
            }
        }

        public  void RemoveTeam(Team tm)
        {
            if (_teams.Contains(tm)){
                _teams.Remove(tm);
            }
        }  
    }
}

I am not sure whether my mapping and entity class is well defined?

Suppose I have following data in my table

tblTeam
        TeamID     |      TeamName
        --------------------------
          1        |         A
        --------------------------
          2        |         B

tblEmployee
        EmployeeID |      EmployeeName
        ------------------------------
          1        |      Jhon
        ------------------------------
          2        |      Michel
        ------------------------------
          3        |      Lino

tblTeamEmployee
        TeamID     |      EmployeeID
        ------------------------------
          1        |      1
        ------------------------------
          1        |      2
        ------------------------------
          2        |      3
        ------------------------------
          2        |      1        

How can I remove Employee name=’Jhon’ from Team=’B’ in ASP.NET page?

  • 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-06-05T15:34:52+00:00Added an answer on June 5, 2026 at 3:34 pm

    As you want to change your collection, remove the .AsReadOnly() from it.

    Then, if you have the ids of both (1 and 2), just do:

    var teamB = session.Get<Team>(2);
    teamB.Employees.Remove(teamB);
    session.Flush();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Warning: I am still very new to NHibernate and Fluent! I have a mapping
I am new to NHibernate and have just started right now. I have very
I have a simple ASP.NET MVC + OpenID + NHibernate app (on top of
I've have quite small asp.net MVC 2 application to maintain/extend. Currently it uses hand
Hey Guys I would very much appreciate some help with the following. We're using
I am very new to NHibernate, and am little confused on where features should
Very new to .Net. Everything was working fine until I added <Tracking> to my
Very new to Fitnesse, I need to write a test using regular expressions to
Very new to using Raphael.js I'm looking at the tutorials and I am able
I am using Wcf in Sharp Architecture. I have configured my project following northwind

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.